python删除某路径下的文件

import os
# import traceback
# os.system('start "" /d "C:\Windows" "regedit.exe"')

my_file = 'D:/hha.txt' # 文件路径
if os.path.exists(my_file): # 如果文件存在
    #删除文件,可使用以下两种方法。
    os.remove(my_file) # 则删除
    #os.unlink(my_file)
else:
    print('no such file:%s'%my_file)

猜你喜欢

转载自blog.csdn.net/qq_38409301/article/details/84966267