我使用脚本扫描整个用户的驱动器C以获取特定文件,然后将结果记录在网络上的txt中。它就像一个魅力。
这是剧本:
@echo off
pushd C:\
dir /s /a-d "setup.txt" /s "setup2.txt" >nul && (goto printresult) || (goto notfound)
:printresult
dir /s /a-d setup.txt /s setup2.txt >>"\\servidor\pastadelogs\FOUND_%computername%.txt
popd
exit
:notfound
echo "Este PC não possui os arquivos" >>"\\servidor\pastadelogs\NOTFOUND_%computername%.txt
popd
exit
现在我需要改进它,使其在usb驱动器内扫描。我已经有一个代码可以给我usb字母:
@echo off
for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 2^>NUL`) do (
if %%l equ 2 (
echo %%i is a drive letter
)
)
我的两个问题是:
祝你好运
答案 0 :(得分:1)
因为任务也在扫描慢速USB介质,所以在第一次传递时创建一个带有结果的文件是明智的,如果有结果,只需type
数据到目标文件,而不是再次扫描。
这是未经测试的,将检查可移动和本地磁盘:(不包括A:和B:)
已修改
这使用一种方法来选择不包含的驱动器等(在findstr命令中):例如驱动器号和驱动器类型号,ID
删除标头。
@echo off
set "file=%temp%\drivescan.tmp"
for /f "tokens=1,2" %%a in ('wmic logicaldisk get deviceid^,drivetype^|findstr /i /v "a: b: 0 1 4 5 6 ID"') do (
echo Processing drive %%a
(dir /b /s /a-d "%%a\setup.txt" "%%a\setup2.txt")>"%file%" 2>nul
for %%d in ("%file%") do if %%~zd NEQ 0 (
type "%file%" >> "\\servidor\pastadelogs\FOUND_%computername%.txt"
) else (
echo "[%%a] Este PC não possui os arquivos">>"\\servidor\pastadelogs\NOTFOUND_%computername%.txt"
)
del "%file%" 2>nul
)
以下是我用Google搜索的驱动器类型列表:
wmic logicaldisk where drivetype=2 get deviceid, volumename, description
Types
0 => Unknown
1 => No Root Directory
2 => Removable Disk
3 => Local Disk
4 => Network Drive
5 => Compact Disc
6 => RAM Disk
答案 1 :(得分:0)
string[,] matrix = new string[3, 3];
这将针对每个USB驱动器进行处理