无法完成批处理文件

时间:2013-01-28 11:37:32

标签: windows loops batch-file cmd xcopy

: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?

2 个答案:

答案 0 :(得分:1)

wmic为您进行过滤:

:LOOP
for /f %%d in (
  'wmic logicaldisk where description^="Removable Disk" get caption ^| find ":"'
) do (
  xcopy %%d D:\Backup
)
goto LOOP

答案 1 :(得分: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