0
:LOOP    
:: Finds Removable Disk Letter
for /f "tokens=1-3" %%a in ('wmic logicaldisk get caption^, description') do if "%%b %%c"=="Removable Disk" set drive=%%a&goto COPY
:COPY
xcopy %drive% D:\Backup
goto :LOOP

我没有这样的批量经验,我想知道,我该怎么做?: 如果可移动磁盘不存在,不要去 COPY 去 LOOP 吗?

4

2 回答 2

1

让我们wmic为你做过滤:

:LOOP
for /f %%d in (
  'wmic logicaldisk where description^="Removable Disk" get caption ^| find ":"'
) do (
  xcopy %%d D:\Backup
)
goto LOOP
于 2013-01-29T19:38:54.893 回答
0
:LOOP    
:: Finds Removable Disk Letter
for /f "tokens=1-3" %%a in ('wmic logicaldisk get caption^, description') do (
if "%%b %%c"=="Removable Disk" set drive=%%a
if not exist "%%a" goto :LOOP
)
:COPY
xcopy %drive% D:\Backup
goto :LOOP

基本上,如果驱动器不存在,它将返回到:LOOP,如果存在,它将自动下降到:COPY.

于 2013-01-28T11:47:05.983 回答