如何从程序输出程序删除了哪些文件,未删除哪些文件?

时间:2019-04-17 14:32:47

标签: python-3.x

我正在尝试使用python 3.7编写临时文件删除器,但是我似乎无法输出要删除的文件和无法删除的文件,因为它们正在被其他程序使用。

这是供个人使用的,我试图找到任何具有此功能的模块,并且尝试使用'def'创建自己的函数,但以目前的知识和技能我无法做到这一点

def rmtree(path):
    for filename in os.listdir(path):
        shutil.rmtree(str(path), ignore_errors = True)
        print('Deleted %s' % filename)

def delhelp():
    sure = str(input('Are you sure you want to delete all of these files? Y/N\n>>>'))

# Trying to find a way to output both files that were deleted and files that weren't deleted
if sure == 'Y' or sure == 'y':
        rmtree('C:\\Users\\Swangeon\\AppData\\Local\\Temp')
        input('All Done! Press enter to quit: ')
        quit()
    elif sure == 'N' or sure == 'n':
        print('Did not erase any files.')
        input('Press enter to quit: ')
        quit()
    else:
        print('Unknown Command!')
        delhelp()

我希望输出为“无法删除etilqs_128Hsk9bdj0”和“已删除新文件夹”,但我所能做的就是获取输出“ Deleted New Folder”和“ Deleted etilqs_128Hsk9bdj0”

0 个答案:

没有答案