【问题标题】:How to ZIP files recursively in Emacs如何在 Emacs 中递归压缩文件
【发布时间】:2014-12-19 13:20:05
【问题描述】:

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

【问题讨论】:

  • @sds 我知道这个 Z 函数在 dired 中,但是它不适用于子文件夹,因此是一个独特的问题。事实上,我看了那个帖子,意识到它不允许子文件夹。

标签: emacs zip dired


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您可以使用运行命令dired-do-compressZ(取消)压缩单个文件。

    你也可以这样做:

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

    【讨论】:

    • 这是否也允许标记某些文件(可能还有一些文件夹),然后使用此命令将其压缩,还是仅适用于单个文件?
    • 也许在你的 doc-string 中添加一点符号,比如m 移动文件,9 是最好的压缩,v 是详细的,@987654327 @ 是递归的——或者类似的东西,所以当被压缩的文件从之前的位置消失时,用户不会感到惊讶。
    猜你喜欢
    • 2011-05-30
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多