【问题标题】:A directory must be empty before being deleted目录在被删除之前必须为空
【发布时间】:2021-11-25 12:57:57
【问题描述】:

请问我怎么能“删除前目录必须是空的。”在我的 jupyter notebooko 中进行操作

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

【问题讨论】:

  • 请分享您的代码
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python pandas database jupyter-notebook anaconda


【解决方案1】:

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

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.")

【讨论】:

    猜你喜欢
    • 2012-07-24
    • 2010-10-15
    • 1970-01-01
    • 2012-03-04
    • 2013-08-08
    • 2012-08-02
    • 2014-01-07
    • 1970-01-01
    • 2013-09-05
    相关资源
    最近更新 更多