删除前目录必须为空



我怎么能";"目录必须为空才能删除。"在我的jupyter笔记本上做

我不知道怎么做,这是我第一次使用如果我是新手

这段代码检查特定文件夹中的内容。如果在该目录下没有文件,那么我们可以删除该文件夹。

import os

# path of the directory
directoryPath = "D:/My_directory/My_project/Folder_to_Test"

# Comparing the returned list to empty list
if os.listdir(directoryPath) == []:
print("No files found in the directory.")
os.rmdir(directoryPath)
else:
print("Some files found in the directory.")

最新更新