2017-06-16 17 views
1

Racketで空でないディレクトリを削除するには? dirは"/ユーザ/りんご/ライブラリ/ Application Support /葵"であるRacketプログラミング言語の空でないディレクトリを削除

私はこのAPI を呼び出し(削除-ディレクトリdir)、。 exnが見つかった:#(構造体:exn:失敗:ファイルシステム:errnoディレクトリを削除できません) パス:/ Users/apple/Library/Application Support/aoi システムエラー:ディレクトリが空でない; errno = 66#(66.pixix)

(define lib-folder '("/Users/apple/Library/Application Support/aoi")) 
(define (del-lib-folder) 
    (for-each (λ (p) 
       (printf "del lib folder:~a~n" p) 
       (if (directory-exists? p) 
        (delete-directory p) 
        (printf "folder does not exist:~a~n" p))) 
      lib-folder)) 

私は何かを見逃しましたか?

答えて

3

ディレクトリを削除するコマンドは、多くのオペレーティングシステムと同様、ディレクトリが空の場合にのみ機能します。例えば。通常、再帰的な削除が必要な

# rmdir dir 
rmdir: failed to remove 'dir/': Directory not empty 

GNU

に: #lang racket

# rm -r dir 
# 

あなたは再帰的に削除機能delete-directory/filesを持っています。ちょうどあなたがやりたいだろうdelete-directory/filesdelete-directoryを置き換える:あなたが尋ねた、あなたが戻ってそれらのファイルを取得することはありません得るような

(define lib-folder '("/Users/apple/Library/Application Support/aoi")) 
(define (del-lib-folder) 
    (for-each (λ (p) 
       (printf "del lib folder:~a~n" p) 
       (if (directory-exists? p) 
        (delete-directory/files p) 
        (printf "folder does not exist:~a~n" p))) 
      lib-folder)) 

は、ファイルリストのバグが正確でしょうかのように非常に注意してください。

0

使用削除、ディレクトリ/ファイル:

(define lib-folder '("/Users/apple/Library/Application Support/aoi")) 
(define (del-lib-folder) 
(for-each (λ (p) 
      (printf "del lib folder:~a~n" p) 
      (delete-directory/files #:must-exist? #f p)) 
     lib-folder)) 
関連する問題