1

我想知道如何通过 MSDOS 或 VBS 创建脚本/批处理可执行文件,这将执行以下操作。

我有一个名为“ Movies ”的文件夹,该文件夹中有几个子文件夹,其中包含“ jpg,gif,png,srt,sub,avi,mp4,mkv ”等文件。

我需要的是:

0.) 除 ' jpg,gif,png,srt,sub,avi,mp4,mkv ' 以外的所有其他文件,其目录已满或为空,必须移至垃圾箱或删除。

1.) 然后我需要在每个子文件夹下创建一个名为“字幕”的新文件夹。

2.)然后将每个子文件夹' jpg,gif,png '文件下的文件重命名为'海报1 ','海报2 ','海报3 '等等......(扩展名没有变化)。

3.) 然后我需要将“ srt,sub ”文件移动到创建的“字幕”文件夹中。

4.) 然后根据电影文件名重命名“ srt,sub ”文件以及包含电影文件的文件夹本身。电影文件可以有扩展名:' avi,mp4,mkv '。

5.) 这个可执行文件必须从“电影”文件夹中运行,如果可能的话,还可以在屏幕上输出结果(看看做了什么)。

所以基本上在文件夹'电影'下将是例如文件夹'疼痛(2011) ',其中将包含'海报1.jpg '、'海报2.jpg '、'海报?.jpg '文件一个名为'字幕'的子文件夹其中将是“ Pain (2011).srt ”文件,至少文件夹本身的名称和字幕文件将以电影文件“ Pain (2011).avi ”命名。当然,所有其他文件都将被移至垃圾箱或删除。

每个想法都非常感谢!

谢谢!

起诉


输出:


按任意键继续 。. .
文件“monsieur_lazhar_.jpg”重命名为“海报 1.jpg”
文件“monsieur_lazhar__ver2.jpg”重命名为“海报 2.jpg”
文件“海报 1.jpg”重命名为“海报 3.jpg”
按任意键继续。. .


///文件夹里只有2个jpg文件,其中一个被重命名了两次

4

1 回答 1

0
@echo off
setlocal EnableDelayedExpansion

set wantedExt=.jpg.gif.png.srt.sub.avi.mp4.mkv

rem I have one folder called 'Movies'
rem This executable file has to be run from the 'Movies' folder
cd /D "%~DP0"
echo BASE FOLDER: %cd%
rem in this folder are several sub-folders with files
set n=0
for /D %%a in (*) do (
   set /A n+=1
   cd "%%a"
   echo ==================================================================
   echo Processing folder: %%a

   rem 0.) Every other file except of 'jpg,gif,png,srt,sub,avi,mp4,mkv' must be moved to trash or deleted.
   for %%b in (*.*) do (
      if "!wantedExt:%%~Xb=!" equ "%wantedExt%" ECHO del "%%b" & echo File deleted: %%b
   )

   rem 0.5.) delete all folders before the 'Subtitles' folder is created
   for /D %%b in (*) do rd /S /Q "%%b"

   rem 1.) Then I need to create under every sub-folder a new folder called 'Subtitles'.
   ECHO md Subtitles
   echo Subtitles folder created

   rem 2.) Then to rename under every sub-folder 'jpg,gif,png' file to 'Poster 1', 'Poster 2', 'Poster 3' and so on... (no change on extension).
   set i=0
   for %%b in (*.jpg *.gif *.png) do (
      set /A i+=1
      ECHO ren "%%b" "Poster !i!%%~Xb"
      echo File "%%b" renamed to "Poster !i!%%~Xb"
   )
   rem PATCH to fix a bug in previous FOR command:
   if !i! neq 0 if not exist "Poster 1.*" (
      ren "Poster !i!.*" "Poster 1.*"
      echo ...and renamed back to "Poster 1"
   )

   rem 3.) Then I need to move the 'srt,sub' file in to the created 'Subtitles' folder.
   rem 4.) ... (to rename the 'srt,sub' file ... according the movie file name)
   rem The movie file can have extension: 'avi,mp4,mkv'.
   for %%b in (*.avi *.mp4 *.mkv) do set movieName=%%~Nb
   echo Movie name: !movieName!
   for %%b in (*.srt *.sub) do (
      ECHO move "%%b" "Subtitles\!movieName!%%~Xb"
      echo File "%%b" moved and renamed to "Subtitles\!movieName!%%~Xb"
   )

   rem 4.) ... (to rename the folder itself which contains the movie file, according the movie file name)
   cd ..
   ECHO ren "%%a" "!movieName!"
   echo Folder "%%a" renamed to "!movieName!"

)
echo ==================================================================
echo %n% FOLDERS PROCESSED
pause
于 2012-12-02T05:09:38.787 回答