2014-12-19 7 views
1

Zip에 폴더를 추가하려고 시도하는 곳에서 Dired로 파일을 압축하는 방법, 재귀 적으로 해당 파일을 추가하는 방법은 무엇입니까?Emacs에서 재귀 적으로 ZIP 파일을 만드는 방법

+0

가능한 [Emacs에서 마크 된 파일을 압축하는 방법] (http://stackoverflow.com/questions/10226836/how-to-tar-and-compress-marked-files-in- 이맥스) – sds

+0

@sds 나는 dired에서이 Z 기능을 알고 있지만 하위 폴더에서는 작동하지 않으므로 고유 한 질문입니다. 사실, 나는 그 포스트를보고 그것이 서브 폴더를 허용하지 않는다는 것을 깨달았다. – PascalVKooten

답변

0

Z을 사용하여 개별 파일을 압축하거나 해제 할 수 있습니다.이 파일은 dired-do-compress 명령을 실행합니다. , m

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

특정 파일 (및 일부 폴더)을 표시 한 다음이 명령으로 압축하거나 단일 파일에서만 작동합니까? – PascalVKooten

+0

아마도 doc-string에 약간의 표기법을 추가하면'm'과 같은 zip 인수가 파일을 옮기고 '9'는 압축률이 가장 높으며'v'는 자세한 정보이고'r'은 재귀 적입니다. 이렇게하면 압축 된 파일이 이전 위치에서 사라질 때 사용자가 놀라지 않을 것입니다. – lawlist

0

마크 파일을 다음 !를 누르고 zip -r yourfile.zip *을 입력

는 또한 같은 것을 할 수 있습니다.