help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [works on the comman line] (was: [a directory is also created])


From: Emanuel Berg
Subject: Re: [works on the comman line] (was: [a directory is also created])
Date: Mon, 21 Feb 2022 05:18:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Uwe Brauer and then Jean Louis wrote:

> On the command line 
> zip -9 -j test.zip test.tex 
> 
> Works but emacs or dired adds a directory, who is here
> the culprit?

Actually, both are correct :)

It is because of the relative path where you are when you run
the command in the shell, OTOH in the Elisp code you give zip
the path.

See the man file for zip(1):

  By default, zip will store the full path (relative to the
  current directory).

The option you are looking for is '--junk-path'.

> You can do it in single function here:
>
> (defun rcd-zip-file ()
>   "ZIP single file within Dired."
>   (interactive)
>   (let* ((file (car (dired-get-marked-files t)))
>        (zip-file (concat file ".zip")))
>     (when file
>       (start-process "ZIP" "ZIP" "zip" "-9" zip-file file)
>       (revert-buffer))))

Yeah, but why have a specific function for a single file, if
it is based on files first being marked anyway? If that's the
method it is better to have a generic function and if one
wants to zip a zingle file, just mark that and nothing else,
if you want more, then instead you do that?

Try this:

(defun dired-zip-files ()
  (interactive)
    (dolist (f (dired-get-marked-files))
      (start-process "zip" nil "zip" "-9" "--junk-path" (concat f ".zip") f)
      (revert-buffer) ))

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]