更新时间:2022-11-28 19:32:54
此方法更简单:
setlocal
for /F "tokens=1,2* delims=_" %%a in ('dir /B *_*_*.pdf *_*_*.png') do (
if not exist "%%a" md "%%a"
if not exist "%%a\%%b" md "%%a\%%b"
move "%%a_%%b_%%c" "%%a\%%b\%%c"
)
即:dir /B *_*_*.pdf
命令产生具有PREFIX_PREFIX2_filename.pdf
格式的名称列表. for /F "tokens=1,2* delims=_" %%a
通过以下方式将此类名称分为3个标记:%%a=PREFIX
,%%b=PREFIX2
和%%c=filename.pdf
.其余的很明显...
That is: dir /B *_*_*.pdf
command produce a list of names with PREFIX_PREFIX2_filename.pdf
format. for /F "tokens=1,2* delims=_" %%a
divide such names in 3 tokens this way: %%a=PREFIX
, %%b=PREFIX2
and %%c=filename.pdf
. The rest is obvious...
PS-我建议您将标题中的sort
单词更改为move
.第一项提出了完全不同的任务的想法...
PS - I suggest you to change the sort
word in your title to move
. The first term gives the idea of an entirely different task...