Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch script using 7 zip

I have the below folder structure, I want to zip all the files and folders within the folder.

Master Directory
File 1
File 2

SubFolder1
ABC Folder
file 1
XYZ Folder
file 1

And I'm using the below code, when I run it I am able to zip sub folders in the master directory and their sub folder and files. But not able to zip files inside the master directory.

CD /d D:\reports
for /d %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a  "D:\Report.zip" "%%X"

How to zip all the contents in the master folder. Any help will be appreciated.

like image 363
Bharath Kashyap Avatar asked Jun 19 '26 00:06

Bharath Kashyap


1 Answers

Why not just:

"C:\Program Files\7-Zip\7z.exe" a "D:\Report.zip" "D:\reports\"

It will compress all files and subfolders inside D:\reports\ into D:\Report.zip.

If you don't want the top reports folder inside the zip but just the subfiles and subfolders, use this:

"C:\Program Files\7-Zip\7z.exe" a "D:\Report.zip" "D:\reports\*"
like image 162
Tiw Avatar answered Jun 21 '26 21:06

Tiw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!