批处理脚本,在变量下设置多个目录?

时间:2015-03-31 17:01:05

标签: variables batch-file directory move

我正在构建文件排序脚本,我希望它使用相同的变量搜索多个源文件夹。这是怎么做到的?

小例子;

@echo off
SET "sourcedir=%a%"

SET "softdir=P:\=Programs"

SET "%a%=C:\downloads1"
SET "%a%=S:\downloads2"
SET "%a%=O:\downloads3"

:progs
IF EXIST "%a%\*.rar" (MOVE /-y "%a%\*.rar" "%softdir%\" )
IF EXIST "%a%\*.exe" (MOVE /-y "%a%\*.exe" "%softdir%\" )
IF EXIST "%a%\*.iso" (MOVE /-y "%a%\*.iso" "%softdir%\" )

1 个答案:

答案 0 :(得分:0)

for将为您做什么:

for %%i in ("c:\downloads1" "s:\downloads2" "o:\downloads") do (
  echo processing %i ...
  if exist "%i\*.rar (MOVE /-y "%i\*.rar" "%softdir%\" )
)