Xah Lee
Xah Lee

Reputation: 17555

creating zip without recording root paths; programmatically

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?

Upvotes: 5

Views: 2022

Answers (2)

this.josh
this.josh

Reputation: 683

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.

Upvotes: 4

Tim Perry
Tim Perry

Reputation: 3096

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

Upvotes: 4

Related Questions