我试图使用此代码删除文件,并且收到“YES 文件存在”,但在 os.remove 上出现错误。
代码
os.chdir('C:/Users/USERNAME/Desktop/WhatsApp Documents/7K1')
if os.path.exists("file.jpg"):
print('YES File is Present')
os.remove('file.jpg')
else:
print('NO')
错误
PermissionError: [WinError 5] Access is denied: 'file.jpg'
最佳答案
试试这个:
import os
os.remove("ChangedFile.csv")
print("File Removed!")
关于python - 从 python 脚本中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59341939/