我的上游主机已更改了它们发送视频文件的方式,现在我有数十个文件夹,其中包含同一文件的MP4和MKV版本。我想保留更高质量的MKV文件并删除MP4版本,但是手动处理的工作太多了,而且在我弄清楚之前,这种情况可能还会不断发生。
因此,我想运行一个脚本/批处理文件,该文件基本上以递归方式查看运行它的目录中的所有子目录, if exist <filename>.mkv, delete <filename>.* unless <filename>.nfo
这些文件位于由Unraid驱动的NAS上,因此我可以在盒子中直接插入并使用Linux,也可以使用Ubuntu或Windows计算机通过网络共享进行操作,因此我在//位置非常灵活这是如何运行的。
在此先感谢您的协助。我一直在扯头发,谷歌搜索以查看是否可以找到解决方案,但是空了出来。
将以下内容放入.cmd文件(或.bat文件)中,并在要开始扫描和删除重复视频文件的根目录/根目录中执行该文件。
该脚本将删除与同一目录中的.mkv文件具有相同文件名的所有文件。但是,它不会删除任何.nfo文件。
此外,脚本将相同的过程递归地应用于所有子目录。
注意的用法setlocal
。该脚本利用了延迟的环境变量扩展。但是,这存在吞没可能是变量内容一部分的感叹号的问题。为避免不必要的消除感叹号,仅在必要时才启用延迟的环境变量扩展。
@echo off
setlocal enableextensions disabledelayedexpansion
echo Processing directory: "%CD%"
rem The outer for-loop goes through all ".mkv" files in the current folder.
rem The inner for-loop goes through all files with the same base file name
rem as the ".mkv" file and deletes them if its file extension is
rem neither ".mkv" nor ".nfo".
for %%i in (*.mkv) do (
set BaseFileName=%%~ni
setlocal enabledelayedexpansion
for %%j in ("!BaseFileName!.*") do (
set FileExtension=%%~xj
if /i {!FileExtension!} neq {.mkv} if /i {!FileExtension!} neq {.nfo} (
setlocal disabledelayedexpansion
echo Deleting %%j
del /q /f "%%j"
endlocal
)
)
endlocal
)
rem This for-loop is responsible for the recursion into sub directories.
set BatchFileAbsolutePath=%~df0
for /d %%i in (*.*) do (
pushd "%%i"
call "%BatchFileAbsolutePath%"
popd
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句