批处理脚本,在变量下设置多个目录?
Batch Script, set multiple directories under variable?
我正在构建一个文件排序脚本,我希望它使用同一个变量搜索多个源文件夹。这是怎么做到的?
小例子;
@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%\" )
也就是说,for
会为您做什么:
for %%i in ("c:\downloads1" "s:\downloads2" "o:\downloads") do (
echo processing %i ...
if exist "%i\*.rar (MOVE /-y "%i\*.rar" "%softdir%\" )
)
我正在构建一个文件排序脚本,我希望它使用同一个变量搜索多个源文件夹。这是怎么做到的?
小例子;
@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%\" )
也就是说,for
会为您做什么:
for %%i in ("c:\downloads1" "s:\downloads2" "o:\downloads") do (
echo processing %i ...
if exist "%i\*.rar (MOVE /-y "%i\*.rar" "%softdir%\" )
)