FL.Alx
FL.Alx

Reputation: 71

Move files of specific extension to individual compressed archives

I want to search files by filename extension and pack each found file in a separate archive (one by one) and delete files after compression. The archive files should be stored in place where files were found.

I expect to identify two parameters for this task: the path to the folder where files should be found and filename extension(s) of these files.

For example:

The path: d:\folder\ Extension: txt

The found name should be transferred to the 7zip and packing should be started:

7z a -mx9 -sdel d:\folder\subfolder1\filename1.txt.7z d:\folder\subfolder1\filename1.txt

and after it will be packed and deleted:

7z a -mx9 -sdel d:\folder\subfolder2\filename2.txt.7z d:\folder\subfolder2\filename2.txt

I've found how to search using the command line: @If "%1"=="" (Set pathf=D:\folder\) else (Set pathf=%1) @If "%2"=="" (Set exmf=*.txt) else (Set exmf=%2)

but I don't know how to send this information to 7zip in correct format. There is no problem with deleting files, because 7zip has -sdel option that solves the problem.

Upvotes: 0

Views: 48

Answers (1)

Klitos Kyriacou
Klitos Kyriacou

Reputation: 11621

Once you've set your variables using the commands from your question, just add this line:

for /r "%pathf%" %%f in ("%exmf%") do 7z a -mx9 -sdel "%%f.7z" "%%f"

Upvotes: 1

Related Questions