考虑一个父文件夹
C:\Users\..\Parent
在父母下面有三个文件夹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_09mea4567_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下的所有文件夹执行此操作。
请注意:这是一台机器上的设置。 在一个不同的机器,而不是德语有一些其他的语言。
希望我让自己更清楚。
@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" ) ) )
目录创建和文件移动被回显到控制台。 如果输出正确,则在md
前移除echo
命令并move
以使其工作。