Pythonでフォルダーを再帰的に削除する
空のディレクトリの削除に問題があります。これが私のコードです: for dirpath, dirnames, filenames in os.walk(dir_to_search): //other codes try: os.rmdir(dirpath) except OSError as ex: print(ex) 引数dir_to_searchは、作業を行う必要があるディレクトリを渡す場所です。そのディレクトリは次のようになります。 test/20/... test/22/... test/25/... test/26/... 上記のフォルダはすべて空であることに注意してください。私は、フォルダにこのスクリプトを実行すると20、25一人で削除されます!しかし、フォルダ25とは26、彼らが空のフォルダであっても、削除されません。 編集: 私が得ている例外は次のとおりです: [Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test' [Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012' [Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10' [Errno 39] Directory not empty: '/home/python-user/shell-scripts/s3logs/test/2012/10/29' [Errno 39] …