我想知道如何通过MSDOS或VBS创建脚本/批处理可执行文件,这样做会有以下几点。
我有一个名为“电影”的文件夹,在这个文件夹中有几个子文件夹,文件包括' 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 '文件,至少文件夹本身和字幕文件的名称将以电影文件“痛苦(2011).avi 命名”。当然,所有其他文件都将被移至垃圾箱或删除。
非常感谢每个想法!
谢谢!
苏
输出:
按任意键继续。 。 。
文件“monsieur_lazhar_.jpg”改名为“Poster 1.jpg”
文件“monsieur_lazhar__ver2.jpg”改名为“Poster 2.jpg”
文件“Poster 1.jpg”改名为“Poster 3.jpg”
按任意键继续 。 。
///只有2个jpg文件,其中一个重命名为两次
答案 0 :(得分: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