-1

I have the following folder structure:

-Videos
  -1. Summer
    summer.mp4
    summer.srt
    summer2.zip
  -2. Winter
    winter.mkv
    winter.vtt
  - ..

How can I create a batch or powershell script that results in the following folder structure:

-Videos
  -1. Summer
    summer.mp4
    1. Summer.7z
  -2. Winter
    winter.mkv
    2. Winter.7z
  - ..

So basically iterate through all sub-folders, zip all the contents except video formats using 7zip and delete the original files that were zipped. I'm open to suggestions using VB!

Chris aa
  • 74
  • 5
  • 1
    Open any plain text editor, and type your code within it before saving it with a `ps1`/`.cmd` extension. – Compo Oct 09 '19 at 01:12

1 Answers1

0

After 2 weeks of research I managed to do it myself. Here's the answer for anyone with a similar situation:

@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

The first for loop iterates through the every subfolder of the root folder while the second for loop iterates through each subfolder of the root folders subfolders. After that

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

after that the del deletes the archived files.

Chris aa
  • 74
  • 5