【发布时间】:2009-09-16 06:48:55
【问题描述】:
我想在 dired 或类似 dired 的缓冲区中运行 unzip(甚至 zip)。有这样的吗?我想要类似于 Nautilus 文件管理器中的内容:即选择文件,然后按一个键将这些文件放入一个新的存档文件中。
谢谢
【问题讨论】:
我想在 dired 或类似 dired 的缓冲区中运行 unzip(甚至 zip)。有这样的吗?我想要类似于 Nautilus 文件管理器中的内容:即选择文件,然后按一个键将这些文件放入一个新的存档文件中。
谢谢
【问题讨论】:
你有选择......
要解压 .zip 文件,您只需添加变量'dired-compress-file-suffixes
(eval-after-load "dired-aux"
'(add-to-list 'dired-compress-file-suffixes
'("\\.zip\\'" ".zip" "unzip")))
现在 dired 中的 Z 键将识别 .zip 扩展名并解压缩 .zip 存档。已经支持gunzip、bunzip2、uncompress 和dictunzip。
如果您想标记文件并将它们添加到 .zip 存档中,您可以使用以下命令将 z 绑定到 zip 标记文件集:
(eval-after-load "dired"
'(define-key dired-mode-map "z" 'dired-zip-files))
(defun dired-zip-files (zip-file)
"Create an archive containing the marked files."
(interactive "sEnter name of zip file: ")
;; create the zip file
(let ((zip-file (if (string-match ".zip$" zip-file) zip-file (concat zip-file ".zip"))))
(shell-command
(concat "zip "
zip-file
" "
(concat-string-list
(mapcar
'(lambda (filename)
(file-name-nondirectory filename))
(dired-get-marked-files))))))
(revert-buffer)
;; remove the mark on all the files "*" to " "
;; (dired-change-marks 42 ?\040)
;; mark zip file
;; (dired-mark-files-regexp (filename-to-regexp zip-file))
)
(defun concat-string-list (list)
"Return a string which is a concatenation of all elements of the list separated by spaces"
(mapconcat '(lambda (obj) (format "%s" obj)) list " "))
【讨论】:
Z 将单独压缩文件。它不会将它们添加到存档/zip。
2010_12_HEAD_Seminar (1).pdf,看看会发生什么。
要压缩文件,请打开目录中的目录。使用m 标记您要压缩的文件。然后输入
! zip foo.zip * <RET>
要从 dired 中提取整个存档,您可以标记一个文件并运行 & unzip,就像在 shell 中一样。
zip-archive 模式将允许您以类似 dired 的方式浏览 zip 文件。它应该随最新版本的 GNU emacs 一起提供,并且在您访问具有 .zip 扩展名的文件时默认使用。在此模式下,您可以将单个文件提取到缓冲区中,然后使用C-x C-s 保存它们。
【讨论】: