1

我有 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 个字符的文件夹......我想要做的是批处理识别文件名并停在-并移动到文件夹......

谢谢你的时间 :)

4

1 回答 1

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
于 2013-01-23T01:16:34.287 回答