我有1000个文件,后缀为-PRO1
和-PPR2
(每个1000个),所以我有1000个文件夹,名称相同但没有后缀......
例如,我有一个名为Abstract_Colorful
的文件夹,我有Abstract_Colorful-PRO1
和Abstract_Colorful-PPR2
等文件,等等......
我想制作批处理以便能够自动移动所有文件,我有这个代码(来自其他帖子)
@echo off
setlocal enabledelayedexpansion
pushd "C:\Folders\"
for %%a in (*) do (
set fldr=%%~na
set fldr=!fldr:~0,4!
md "!fldr!"
move "%%a" "!fldr!"
)
popd
pause
exit
但它的作用是,如果文件有超过4个字符,它会创建一个包含前4个字符的文件夹...我想要做的是批处理识别文件名并停在-
并移动到文件夹...
感谢您的时间:)
答案 0 :(得分:1)
@echo off
pushd "C:\Folders"
rem Process all files in this folder separating the names at "-"
for /F "tokens=1* delims=-" %%a in ('dir /B *.*') do (
rem At this point %%a have the name before the "-" and %%b the rest after "-"
rem Create the folder, if not exists
if not exist "%%a" md "%%a"
rem Move the file there
move "%%a-%%b" "%%a"
)
popd