所以我是 python 的新手,我有一个需要分成两部分的函数。以前它是一个函数,但经过比我更了解的人的一些建议,我得到提示,我的函数做得太多了,我需要将其分解为两个独立的事情;所以我来了。
下面是分成两部分的代码。
我想知道我必须pathlist在这两个函数中都提到吗?
这应该做的是检查文件是否存在,然后如果它们存在,则运行第二个函数以删除实际目录。
def check_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
remove_directory(pathslist)
dirs_to_delete = [
'C:\MyDirectoryPath1',
'C:\MyDirectoryPath2',
'C:\MyDirectoryPath3'
]
def remove_directory(pathslist):
for path in pathslist:
if os.path.exists(path) and os.path.isdir(path):
shutil.rmtree(path)
print(colored('Found ' + path + ' removing', 'green'))
心有法竹
相关分类