如何在Emacs中递归压缩文件

如何在Emacs中递归压缩文件,emacs,zip,dired,Emacs,Zip,Dired,如何在Dired中压缩文件,如果尝试将文件夹添加到zip中,它还会递归地将文件添加到该文件夹中?您可以使用运行该命令的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-nondi

如何在Dired中压缩文件,如果尝试将文件夹添加到zip中,它还会递归地将文件添加到该文件夹中?

您可以使用运行该命令的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
标记文件,然后按
并键入
zip-r yourfile.zip*

可能与@sds重复我知道dired中的这个Z函数,但是,它不适用于子文件夹,因此是一个独特的问题。事实上,我看了那篇文章后意识到它不允许子文件夹。这是否也允许标记某些文件(可能还有一些文件夹),然后使用此命令将其压缩,还是只对单个文件有效?也许在文档字符串中添加一点符号,例如
m
压缩参数可以移动文件,
9
是最好的压缩,
v
是详细的,而
r
是递归的——或者类似的东西,因此当正在压缩的文件从以前的位置消失时,用户不会感到惊讶。