【发布时间】:2021-11-25 12:57:57
【问题描述】:
请问我怎么能“删除前目录必须是空的。”在我的 jupyter notebooko 中进行操作
我不知道该怎么做,这是我第一次使用 我也是新手
【问题讨论】:
-
请分享您的代码
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: python pandas database jupyter-notebook anaconda
请问我怎么能“删除前目录必须是空的。”在我的 jupyter notebooko 中进行操作
我不知道该怎么做,这是我第一次使用 我也是新手
【问题讨论】:
标签: python pandas database jupyter-notebook anaconda
此代码检查特定文件夹中的内容。 如果在该目录中没有找到文件,那么我们可以删除该文件夹。
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.")
【讨论】: