Windows批处理根据名称将文件移动到单个文件夹中

时间:2013-12-25 06:56:40

标签: batch-file

我正在使用Windows 7 64位。我有两组图像命名为:

Pro_NGF_Con_Parallel001.TIFF
Pro_NGF_Con_Parallel001.TIFF

Pro_NGF_Con_Orthogonal001.TIFF
Pro_NGF_Con_Orthogonal002.TIFF

我需要一个批处理脚本,可以根据其名称将它们排序到文件夹001002

  • 001
    • Pro_NGF_Con_Parallel001.TIFF
    • Pro_NGF_Con_Orthogonal001.TIFF
  • 002
    • Pro_NGF_Con_Parallel002.TIFF
    • Pro_NGF_Con_Orthogonal002.TIFF

然后我需要另一个批处理脚本来重命名每个子文件夹中的文件:

  • 001
      来自 Parallel.TIFF
    • Pro_NGF_Con_Parallel001.TIFF 来自 Perp.TIFF
    • Pro_NGF_Con_Orthogonal001.TIFF
  • 002
      来自 Parallel.TIFF
    • Pro_NGF_Con_Parallel002.TIFF 来自 Perp.TIFF
    • Pro_NGF_Con_Orthogonal002.TIFF

1 个答案:

答案 0 :(得分:1)

批次1:

@echo off
setlocal enabledelayedexpansion
for /L %%a in (1000,1,1999) do (
set "num=%%a"
set "num=!num:~-3!"
   if exist "*!num!.tiff" (
      md "!num!" 2>nul
      move "*!num!.tiff" "!num!"
   )
)

批次2:

@echo off
setlocal enabledelayedexpansion
for /L %%a in (1000,1,1999) do (
set "num=%%a"
set "num=!num:~-3!"
   if exist "!num!\*_Parallel!num!.tiff" ren "!num!\*_Parallel!num!.tiff" "Parallel.tiff"
   if exist "!num!\*_Orthogonal!num!.tiff" ren "!num!\*_Orthogonal!num!.tiff" "Perp.tiff"
)