之前,我将mp4视频文件转换为mp3音频文件。现在我想删除原始mp4视频文件使用
os.remove
但是,当我执行代码时,它会显示一个错误,如下所示:
Win32 error : The process cannot access the file because it is being used by another process
下面是我的代码:
try:
global stram
b2.config(text="Please wait...")
b2.config(state=DISABLED)
stream = yt.streams.filter(progressive=True)
path = filedialog.askdirectory()
if path == None:
return
stream[0].download(path)
for i in os.listdir(path):
os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))
title = yt.title.replace(' ','_')
video = VideoFileClip(os.path.join(path+"/"+title+".mp4"))
video.audio.write_audiofile(os.path.join(path+"/"+title+".mp3"))
l3 = Label(action,text="Download Complete",font=("Calibri",12),fg = "green").pack()
b2.config(text="Download Audio")
try:
file = str(f'{title}.mp4')
os.remove(os.path.join(path,file))
except Exception as e:
print(e)
except Exception as e:
l3 = Label(action,text="Error occured while Downloading",font=("Calibri",12),fg = "red").pack()
有人知道为什么会发生这种错误吗?非常感谢你的帮助。提前谢谢
谈到windows,我不是专家,但我认为“另一个过程”实际上指的是您的python脚本,或者您在python脚本中使用的模块。我猜想您应该找到一种方法来关闭
video
变量基于this,您应该能够在
os.remove
之前执行video.close()
相关问题 更多 >
编程相关推荐