空のディレクトリの削除に問題があります。コードは次のとおりです。
os.walk(dir_to_search)のdirpath、dirnames、filenamesの場合://他のコードは次のようになります:os .rmdir(dirpath)ex:print(ex)
引数dir_to_search
は、作業を行う必要のあるディレクトリを渡す場所です。 。そのディレクトリは次のようになります:
test / 20 / ... test / 22 / ... test / 25 / ... test / 26 / ...
上記のフォルダはすべて空であることに注意してください。このスクリプトを実行すると、フォルダ 20
、 25
だけが削除されます。ただし、フォルダ 25
と26
は、空のフォルダであっても削除されません。
編集:
例外私が取得しているのは次のとおりです。
[Errno 39]ディレクトリが空ではありません: "/ home / python-user / shell-scripts / s3logs / test" [Errno 39]ディレクトリが空ではありません: " / home / python-user / shell-scripts / s3logs / test / 2012 "[Errno 39]ディレクトリが空ではありません:" / home / python-user / shell-scripts / s3logs / test / 2012/10"[Errno39]ディレクトリ空ではない: "/ home / python-user / shell-scripts / s3logs / test / 2012/10/29" [Errno 39]ディレクトリが空ではない: "/ home / python-user / shell-scripts / s3logs / test / 2012 / 10/29 / tmp "[Errno 39]ディレクトリが空ではありません:" / home / python-user / shell-scripts / s3logs / test / 2012/10/28 "[Errno 39]ディレクトリが空ではありません:" / home / python -user / shell-scripts / s3logs / test / 2012/10/28 / tmp "[Errno 39]ディレクトリが空ではありません:" / home / python-user / shell-scripts / s3logs / test / 2012/10/26 "[ Errno 39]ディレクトリが空ではありません: "/ home / python-user / shell-scripts / s3logs / test / 2012/10/25" [Errno 39]ディレクトリが空ではありません: "/ home / python-user / shell-scripts / s3logs / test / 2012/10/27 "[Errno 39]ディレクトリが空ではありません:" / home / python-user / shell-scripts / s3logs / test / 2012/10/27 / tmp "
どこで間違いを犯しているのですか?