将基于扩展名的文件移动到子文件夹中

时间:2013-06-11 12:25:07

标签: batch-file move directory

我正在查找将进入子目录的for循环,并将扩展名为mp4和flv的文件移动到文件夹中调用Media。

  Folder structure is as follows: 
  Folder 1 (Parent) (Where bat file would go)
    Folder 1 Sub (First Sub-folder)
      Media (Folder)            
      File_Name.Mp4
      File_Name.flv
    Folder 2 Sub (Second Sub-folder)
      Media (Folder)            
      File_Name.Mp4
      File_Name.flv
    Folder 3 Sub (Third Sub-folder)
      Media (Folder)            
      File_Name.Mp4
      File_Name.flv
      And so on..... I have about 1100 sub-folders in Folder 1 (parent folder 

谢谢你看看这个。

2 个答案:

答案 0 :(得分:2)

如有必要,请更改开始文件夹Folder 1 (Parent),然后尝试:

@echo off &setlocal
for /r "Folder 1 (Parent)" %%i in (*.mp4 *.flv) do (
    echo("%%~pi"|findstr /ri ".\\Media\\.$" >nul|| echo move "%%~fi" "%%~dpiMedia\%%~nxi"
)

答案 1 :(得分:2)

这是为了处理父级中的所有第1级文件夹,并将mp4和flv文件移动到第一级文件夹中名为media的文件夹中。

未经测试。在一些示例文件夹上测试它。

@echo off
for /f "delims=" %%a in (' dir /ad /b ') do (
pushd "%%a"
md Media 2>nul
for %%z in (mp4 flv) do move *.%%z Media 
popd
)