这是我的建议:
@Echo Off
:: List all files and call :move_2_subfolder -function one file at a time.
FOR %%a IN (*.png) DO Call :move_2_subfolder "%%~a"
GoTo :End
:move_2_subfolder
:: Save the name of the file [without extension] to sub_folder_name -variable.
Set sub_folder_name=%~n1
:: Strip the numbers off.
Set sub_folder_name=%sub_folder_name:0=%
Set sub_folder_name=%sub_folder_name:1=%
Set sub_folder_name=%sub_folder_name:2=%
Set sub_folder_name=%sub_folder_name:3=%
Set sub_folder_name=%sub_folder_name:4=%
Set sub_folder_name=%sub_folder_name:5=%
Set sub_folder_name=%sub_folder_name:6=%
Set sub_folder_name=%sub_folder_name:7=%
Set sub_folder_name=%sub_folder_name:8=%
Set sub_folder_name=%sub_folder_name:9=%
:: Create folder, if necessary.
If not exist "%sub_folder_name%" md "%sub_folder_name%\"
:: Move the file.
Move "%~1" "%sub_folder_name%\"
:: Return to For -command.
GoTo :EOF
:End
If Defined sub_folder_name Set sub_folder_name=
@Echo Off
这不起作用:
For /L %%a IN (0,1,9) DO Set sub_folder_name=%sub_folder_name:%%~a=%*
这也不会:
...
For /L %%a IN (0,1,9) DO Call :strip_numbers "%%~a"
:strip_numbers
Set sub_folder_name=%sub_folder_name:%~1%
GoTo :EOF
出于某种原因,Set -command 不接受%%~a或%~1变量。