@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\t w o"
PUSHD "%sourcedir%"
FOR /f "tokens=1*delims= " %%a IN (
'dir /b /a-d "* *.pdf" '
) DO (
IF EXIST "..\%%a\." (ECHO(MOVE "%%a %%b" "..\%%a\") ELSE (ECHO(Leave "%%a %%b")
)
popd
GOTO :EOF
您需要更改设置sourcedir
以适应您的情况。将其分配给%~dp0
是一种可能性。
给定(部分 dir /a:d of %sourcedir%)
20/01/2015 09:49 <DIR> one
20/01/2015 09:49 <DIR> t w o
20/01/2015 09:50 <DIR> 1232
20/01/2015 09:50 <DIR> 1234
和pdf源的目录:
u:\sourcedir\two 的目录
20/01/2015 09:50 0 dum myfile2.pdf
20/01/2015 09:50 0 1231 54321.pdf
20/01/2015 09:50 0 1232 54321.pdf
20/01/2015 09:50 0 1233 54321.pdf
20/01/2015 09:50 0 1234 54321.pdf
20/01/2015 09:50 0 1235 54321.pdf
6 File(s) 0 bytes
这产生
Leave "dum myfile2.pdf"
Leave "1231 54321.pdf"
MOVE "1232 54321.pdf" "..\1232\"
Leave "1233 54321.pdf"
MOVE "1234 54321.pdf" "..\1234\"
Leave "1235 54321.pdf"
所需的 MOVE 命令仅ECHO
用于测试目的。确认命令正确后,更改ECHO(MOVE
为MOVE
实际移动文件。附加>nul
以抑制报告消息(例如1 file moved
)
该Leave
消息及其相关else
子句当然是可选的。