【发布时间】:2014-12-19 13:20:05
【问题描述】:
如何在 Dired 中压缩文件,在尝试将文件夹添加到 zip 时,它还会递归地添加该文件夹中的文件?
【问题讨论】:
-
@sds 我知道这个 Z 函数在 dired 中,但是它不适用于子文件夹,因此是一个独特的问题。事实上,我看了那个帖子,意识到它不允许子文件夹。
如何在 Dired 中压缩文件,在尝试将文件夹添加到 zip 时,它还会递归地添加该文件夹中的文件?
【问题讨论】:
用m 标记文件,然后按! 并输入zip -r yourfile.zip *。
【讨论】:
您可以使用运行命令dired-do-compress 的Z(取消)压缩单个文件。
你也可以这样做:
(defun sds-dired-zip-file ()
"ZIP the current file and all subdir's; or unZIP if already a ZIP."
(interactive)
(let* ((fn (dired-get-filename)) (nd (file-name-nondirectory fn)) cmd msg)
(cond ((and (string-match ".zip$" fn)
(y-or-n-p (format "unzip %s? " fn)))
(setq msg "unZIPing file %s..." cmd (concat "unzip " nd)))
((and (or (string-match ".tgz$" fn) (string-match ".tar.gz$" fn))
(y-or-n-p (format "tar xfz `%s'? " fn)))
(setq msg "unTAR/GZIPing file %s..." cmd (concat "tar xfz " nd)))
((and (or (string-match ".tbz2$" fn) (string-match ".tar.bz2$" fn))
(y-or-n-p (format "tar xfj `%s'? " fn)))
(setq msg "unTAR/BZIPing file %s..." cmd (concat "tar xfj " nd)))
((and (string-match ".tar$" fn)
(y-or-n-p (format "tar xf `%s'? " fn)))
(setq msg "unTARing file %s..." cmd (concat "tar xf " nd)))
((and (string-match ".rar$" fn)
(y-or-n-p (format "unrar x `%s'? " fn)))
(setq msg "unRARing file %s..." cmd (concat "unrar x " nd)))
((and (file-directory-p fn)
(y-or-n-p (format "zip -rmv9 `%s'? " fn)))
(setq msg "ZIPing directory %s..."
cmd (concat "zip -rmv9 " nd ".zip " nd)))
((y-or-n-p "(un?)compress? ") (dired-do-compress)))
(when cmd
(message msg fn)
(shell-command (concat "cd " (file-name-directory fn) " && " cmd))
(revert-buffer))))
(define-key dired-mode-map "I" 'sds-dired-zip-file)
【讨论】:
m 移动文件,9 是最好的压缩,v 是详细的,@987654327 @ 是递归的——或者类似的东西,所以当被压缩的文件从之前的位置消失时,用户不会感到惊讶。