更新时间:2021-07-21 08:41:59
@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
.
You would need to change the setting of sourcedir
to suit your circumstances. Assigning it to %~dp0
is a possibility.
给出(%sourcedir%的部分dir/a:d)
Given (partial 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 \ t w o的目录
Directory of u:\sourcedir\t w o
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
)
The required MOVE commands are merely ECHO
ed for testing purposes. After you've verified that the commands are correct, change ECHO(MOVE
to MOVE
to actually move the files. Append >nul
to suppress report messages (eg. 1 file moved
)
Leave
消息及其关联的else
子句当然是可选的.
The Leave
message and its associated else
clause would of course be optional.