如何在Emacs中递归地压缩文件

时间:2014-12-19 13:20:06

标签: emacs zip dired

如何在Dired中压缩文件,在尝试向zip添加文件夹时,它还会递归添加该文件夹中的文件?

2 个答案:

答案 0 :(得分:0)

您可以使用运行命令dired-do-compress Z 来(un)压缩单个文件。

您也可以这样做:

(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)

答案 1 :(得分:0)

使用m标记文件,然后按!并输入zip -r yourfile.zip *