From: ······@gmail.com
Subject: using zip utility without getting all the parent dir in archive
Date: 
Message-ID: <7f065d43-099e-4117-98a0-6147a6e5ea2f@z24g2000prf.googlegroups.com>
is there a way to call the unix zip utility programmatically with full
path as arguments but yet does not have the created zip archive
contain all the nested parent dir?

some detail here:

zip archive created by the zip utility will include the full path up
to root dir when called with full path arguments.

e.g.

zip -r /Users/xah/web/diklo/xx-htmlize-study.zip /Users/xah/web/diklo/
xx-htmlize-study
zip -r /Users/xah/web/diklo/xx-htmlize-study.zip /Users/xah/web/diklo/
xx-htmlize-study

the solution is not to use full path but cd to the dir first. e.g.

cd /Users/xah/web/diklo
zip -r xx-htmlize-study.zip xx-htmlize-study

but i need to call zip programmatically in elisp. I noticed this
works:

(setq default-directory "/Users/xah/web/diklo/")
(shell-command (concat "zip -r " zipCoreName ".zip " zipCoreName))

however, not sure what mechanism it works. Does emacs passes the
current dir into the shell before calling shell-command, then the zip
utility picks it up from shell env?

also, i often needs to do one-line unix command of the form
find . ... | xargs -l -i  zip -r "{}.zip" "{}"

But the reliance on notion of current directory makes this one-liner
impossible ... (for context, using tar gzip with “tar cfz” will work
fine.)

Is there a solution on this?

i was hoping the zip util has a option to set a base dir to be
considered the current dir, but couldn't find it in its man page, or
how to get what i want above.

Thanks in advance.

  Xah
∑ http://xahlee.org/

☄

From: Lew Pitcher
Subject: Re: using zip utility without getting all the parent dir in archive
Date: 
Message-ID: <122e8$4863e197$4c0a8be3$12843@TEKSAVVY.COM-Free>
In comp.unix.programmer, ······@gmail.com wrote:

> is there a way to call the unix zip utility programmatically with full
> path as arguments but yet does not have the created zip archive
> contain all the nested parent dir?

Why not just use the -j option to "junk the path"

       -j     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 path).


See the zip(1) manpage for details
[snip]

HTH
-- 
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/   | GPG public key available by request
----------      Slackware - Because I know what I'm doing.          ------
From: ······@gmail.com
Subject: Re: using zip utility without getting all the parent dir in archive
Date: 
Message-ID: <09d839ae-db29-499b-9f11-a7baf1317d0c@s33g2000pri.googlegroups.com>
> Why not just use the -j option to "junk the path"
>
>        -j     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 path).

I tried the -j option, however, the archive will be just a list of
flat files.

  Xah
∑ http://xahlee.org/

☄

On Jun 26, 12:01 pm, Lew Pitcher <········@teksavvy.com> wrote:
> In comp.unix.programmer, ······@gmail.com wrote:
> > is there a way to call the unix zip utility programmatically with full
> > path as arguments but yet does not have the created zip archive
> > contain all the nested parent dir?
>
> Why not just use the -j option to "junk the path"
>
>        -j     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 path).
>
> See the zip(1) manpage for details
> [snip]
>
> HTH
> --
> Lew Pitcher
>
> Master Codewright & JOAT-in-training | Registered Linux User #112576http://pitcher.digitalfreehold.ca/  | GPG public key available by request
> ----------      Slackware - Because I know what I'm doing.          ------
From: Glenn Willen
Subject: Re: using zip utility without getting all the parent dir in archive
Date: 
Message-ID: <slrng68dpu.435.gwillen@gwillen-mac.local>
In article <····································@z24g2000prf.googlegroups.com>,
  ······@gmail.com wrote:
> is there a way to call the unix zip utility programmatically with full
> path as arguments but yet does not have the created zip archive
> contain all the nested parent dir?

As far as I can tell (and I just read through the manpage for 'zip' on this
system, just to be sure) at least the version I have simply cannot do that.

> the solution is not to use full path but cd to the dir first. e.g.

This is definitely the solution that first came to my mind, and as far as I can
tell it's the only one.

> (setq default-directory "/Users/xah/web/diklo/")
> (shell-command (concat "zip -r " zipCoreName ".zip " zipCoreName))
> 
> however, not sure what mechanism it works. Does emacs passes the
> current dir into the shell before calling shell-command, then the zip
> utility picks it up from shell env?

I would guess that emacs does a cd to the default-directory before calling the
shell command. So yes, it is as you say, assuming by "shell env" you don't mean
the shell's environment variables, but the shell's own current directory.

> also, i often needs to do one-line unix command of the form
> find . ... | xargs -l -i  zip -r "{}.zip" "{}"

Any particular reason you don't use 'find . ... -exec zip -r "{}.zip" "{}"'?

> But the reliance on notion of current directory makes this one-liner
> impossible ... (for context, using tar gzip with ?tar cfz? will work
> fine.)
> 
> Is there a solution on this?

You could do something like 'find . ... | xargs -l -i <somescript> {}

And then write a script in your favorite language to do the rest (the bash
    version follows:)

#!/bin/bash
DIR=${1%/*} # Strip last path component
cd $DIR
FILE=`basename $1` # Grab last path component
zip -r "$FILE.zip" $FILE

Note that this will fail if any input line doesn't contain a slash; I think all
lines output by find will contain slashes.

> Thanks in advance.

No problem. :-)

gwillen