用于压缩特定文件的批处理或Powershell脚本

问题描述 投票:-1回答:1

我具有以下文件夹结构:

-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的建议!

vba powershell batch-file zip 7zip
1个回答
0
投票

经过2周的研究,我自己完成了这项工作。这是遇到类似情况的人的答案:

@echo off
cls
set zip="C:\Program Files (x86)\7-Zip\7z.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

之后删除删除已归档的文件。

© www.soinside.com 2019 - 2024. All rights reserved.