Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing only files using 7z without preserving the path

I am using 7z command line executable to zip files, but I see that while adding to an archive the path of the files is preserved in the archive.

So if I do

7z a -tzip  myzip.zip dir1\dir2\* 

the archive myzip.zip will contain the path dir1\dir2. I do not want this, rather I want only the files to be added to the zip file without the paths being preserved. I searched quite a bit but do not seem to find any way of doing this, maybe I am missing something obvious?

Thanks

like image 912
Raam Avatar asked May 25 '12 11:05

Raam


People also ask

Where does 7zip store compressed files?

Your 7zip file is in folder/. 7z . The output of the command tells you: Creating archive: folder/. 7z .

Can you compress a 7z file?

7-Zip is a free and open-source file archiver for compressing and uncompressing files. If you need to save some disk space or make your files more portable, this software can compress your files into an archive with a . 7z extension.

Does 7z compress better than zip?

In 2011, TopTenReviews found that the 7z compression was at least 17% better than ZIP, and 7-Zip's own site has since 2002 reported that while compression ratio results are very dependent upon the data used for the tests, "Usually, 7-Zip compresses to 7z format 30–70% better than to zip format, and 7-Zip compresses to ...

How do I create a zip folder without a new folder?

To select non-consecutive files or folders, hold down the Ctrl key as you select the individual files and/or folders. 2. Right-click on the file or folder (or group of files or folders), then point to Send to and select Compressed (zipped) folder. 3.


2 Answers

Just add a dot before the path, i.e. 7z a -tzip -r myzip.zip .\Relative\Dir\*

like image 84
Nickolay Olshevsky Avatar answered Oct 07 '22 21:10

Nickolay Olshevsky


Give the full path. That should work. Not the relative path from the current location. For example, I give the below, where I want the files in the man5 folder to be archived.

$ 7z a -tzip myzip.zip /home/pradeeban/Desktop/man4/man5/* 

The zip contained only the files, without the directories.

Then I gave only the relative path. It had the directories, inside the zip.

$ 7z a -tzip myzip.zip Desktop/man4/man5/* 

Tried with Linux (Ubuntu 12.04). Not sure whether that differs from Windows.

like image 34
Pradeeban Kathiravelu Avatar answered Oct 07 '22 20:10

Pradeeban Kathiravelu