Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating zip without recording root paths; programmatically

Tags:

bash

shell

zip

suppose i want to zip this dir 〔c:/Users/xah/ErgoEmacs_Source/ergoemacs/build-util/〕

and my i want the output dir to be 〔c:/Users/xah/xx2/〕

(my current dir could be anywhere. I'm calling zip in a elisp program) so i do

zip -r c:/Users/xah/xx2/build-util.zip c:/Users/xah/ErgoEmacs_Source/ergoemacs/build-util/

then zip will record the full path like this

adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/ (stored 0%)
adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/.svn/ (stored 0%)
adding: Users/xah/ErgoEmacs_Source/ergoemacs/build-util/.svn/all-wcprops (deflated 56%)
...

i want the paths to simply start with build-util.

note: i'm calling zip in a program (elisp) and i cant or don't want to use any concept of envirenment variable.

Is this possible with some zip parameter?

like image 441
Xah Lee Avatar asked Nov 27 '10 12:11

Xah Lee


People also ask

How do I get the full path of a zip file?

Use the -j or --junk-paths option in your zip command. -j --junk-paths Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory). Hope this helps. (cd directory && zip -r ../out.zip .)

How to avoid creating a ZIP archive with the V folder?

When I try to zip it, it ends creating a zip archive with the v folder instead of the contents of it (the sub directories and files) How can I avoid this? Use the -j or --junk-paths option in your zip command. -j --junk-paths Store just the name of a saved file (junk the path), and do not store directory names.

How do I add a zip file to a folder?

cd folder zip -r ../zipped_folder.zip . I use -r option, the "zip filename" and the list of items I want to add into it. Refering to --help option we get: You can go into folder that contains the files and directories you want to zip in. The run the command: zip -r filename.zip ./*

How do I Zip a list of items in a directory?

I use -r option, the "zip filename" and the list of items I want to add into it. Refering to --help option we get: You can go into folder that contains the files and directories you want to zip in. The run the command: zip -r filename.zip ./* The result is a filename.zip containing everything into the directory you ran the command.


2 Answers

Oddly enough, your best option may be to use jar from the Java JDK.

jar -cMf c:/Users/xah/xx2/build-util.zip -C c:/Users/xah/ErgoEmacs_Source/ergoemacs/build-util/ .

the "-M" tells jar not to create a manifest file and the -C tells it to change directories before beginning zipping files up. The documentation I based this off of is here: http://download.oracle.com/javase/tutorial/deployment/jar/build.html

like image 134
Tim Perry Avatar answered Oct 25 '22 19:10

Tim Perry


One of my favorite bash functions is pushd, it saves the dirrectory you are currently in and moves you to the directory you specify. The reciprocal function is popd, it moves you back to the directory you were in before pushd. For example you do

pushd c:/Users/xah/ErgoEmacs_Source/ergoemacs
zip -r c:/Users/xah/xx2/build-util.zip build-util/
popd

I think you wind up with what you want.

like image 38
this.josh Avatar answered Oct 25 '22 19:10

this.josh