2013-12-18 35 views
1

在其名称中的模式考虑父文件夹排序文件到文件夹中基于使用的.bat

C:\Users\..\Parent 

在父母有3个文件夹M1,M2,M3

C:\Users\..\Parent\M1 
C:\Users\..\Parent\M2 
C:\Users\..\Parent\M3. 

在M1,M2 ,M3有100个子文件夹。

C:\Users\..\Parent\M1\MattP001M1 
C:\Users\..\Parent\M1\MattP002M1 
so on till 
C:\Users\..\Parent\M1\MattP100M1. 

类似地对于M2,M3也是如此。


在每个文件夹(MattP001M1..MattP100M1)有一吨的.wav文件(接近1500上的平均值)。 这些wav文件在其命名中有一个模式。 例如:有German_09mea4567_morename 20个文件和German_4132azzi_morename等15个文件。 我正在使用此脚本将它们分组在基于(09mea4567)之后的独特部分的文件夹中。

SETLOCAL ENABLEDELAYEDEXPANSION 
for %%a in (*.wav) do (
set f=%%a 
set g=!f:~7,8! 
md "!g!" 2>nul 
move "%%a" "!g!" 
) 

现在,这是罚款,一个文件夹。我想为M1(MattP001M1,..,MattP100M1),M2,M3下的所有文件夹执行此操作。

请注意:这是一台机器上的设置。在另一台机器上而不是德语上有另一种语言。

希望我让自己更清楚了。

+0

@foxidrive感谢您的编辑。对不起,现在测试 – Matt

回答

1
@echo off 

    rem Prepare environment 
    setlocal enableextensions disabledelayedexpansion 

    rem configure where to start 
    set "root=c:\somewhere" 

    rem For each file under root that match indicated pattern 
    for /r "%root%" %%f in (*_*_*.wav) do (

     rem Split the file name in tokens using the underscore as delimiter 
     for /f "tokens=2 delims=_" %%p in ("%%~nf") do (

      rem Test if the file is in the correct place 
      for %%d in ("%%~dpf.") do if /i not "%%~p"=="%%~nd" (

       rem if it is not, move it where it should be 
       if not exist "%%~dpf\%%~p" echo md "%%~dpf\%%~p" 
       echo move "%%~ff" "%%~dpf\%%~p" 
      ) 
     ) 
    ) 

目录创建和文件移动被回显到控制台。如果输出正确,请在mdmove之前删除echo命令以使其正常工作。

+0

:)谢谢 – Matt

相关问题