用于压缩特定文件的批处理或 Powershell 脚本
Batch or Powershell Script to zip specific files
我有以下文件夹结构:
-Videos
-1. Summer
summer.mp4
summer.srt
summer2.zip
-2. Winter
winter.mkv
winter.vtt
- ..
如何创建生成以下文件夹结构的批处理或 powershell 脚本:
-Videos
-1. Summer
summer.mp4
1. Summer.7z
-2. Winter
winter.mkv
2. Winter.7z
- ..
所以基本上遍历所有子文件夹,使用 7zip 压缩除视频格式之外的所有内容,并删除压缩的原始文件。我愿意接受使用 VB!
的建议
经过 2 周的研究,我设法自己完成了。以下是任何有类似情况的人的答案:
@echo off
cls
set zip="C:\Program Files (x86)-Zipz.exe"
set loc=C:\User\Downloads\Videos\UnConverted
cd %loc%
for /d %%D in (%loc%\*) do (
for /d %%I in ("%%D\*") do (
cd %%I
%zip% a -t7z -mx9 "%%~nxI.7z" *.txt *.html *.vtt *.srt *.zip *.jpeg *.png
del /S *.txt *.html *.vtt *.srt *.zip *.jpeg *.png
)
)
cd %loc%
echo ----- Compression Complete! -----
pause
第一个 for 循环遍历根文件夹的每个子文件夹,而第二个 for 循环遍历根文件夹子文件夹的每个子文件夹。之后
cd %%I - To enter the sub-sub-folder
%zip% - To call the 7z cli
a - add files to archive
t7z - using the .7z extension
mx9 - with maximum compression
%%~nxI.7z - to store the files using the sub-sub-folders name
*.txt *.html *.vtt *.srt *.zip *.jpeg *.png - file extensions to archive
之后 del 删除归档文件。
我有以下文件夹结构:
-Videos
-1. Summer
summer.mp4
summer.srt
summer2.zip
-2. Winter
winter.mkv
winter.vtt
- ..
如何创建生成以下文件夹结构的批处理或 powershell 脚本:
-Videos
-1. Summer
summer.mp4
1. Summer.7z
-2. Winter
winter.mkv
2. Winter.7z
- ..
所以基本上遍历所有子文件夹,使用 7zip 压缩除视频格式之外的所有内容,并删除压缩的原始文件。我愿意接受使用 VB!
的建议经过 2 周的研究,我设法自己完成了。以下是任何有类似情况的人的答案:
@echo off
cls
set zip="C:\Program Files (x86)-Zipz.exe"
set loc=C:\User\Downloads\Videos\UnConverted
cd %loc%
for /d %%D in (%loc%\*) do (
for /d %%I in ("%%D\*") do (
cd %%I
%zip% a -t7z -mx9 "%%~nxI.7z" *.txt *.html *.vtt *.srt *.zip *.jpeg *.png
del /S *.txt *.html *.vtt *.srt *.zip *.jpeg *.png
)
)
cd %loc%
echo ----- Compression Complete! -----
pause
第一个 for 循环遍历根文件夹的每个子文件夹,而第二个 for 循环遍历根文件夹子文件夹的每个子文件夹。之后
cd %%I - To enter the sub-sub-folder
%zip% - To call the 7z cli
a - add files to archive
t7z - using the .7z extension
mx9 - with maximum compression
%%~nxI.7z - to store the files using the sub-sub-folders name
*.txt *.html *.vtt *.srt *.zip *.jpeg *.png - file extensions to archive
之后 del 删除归档文件。