[英]os.rename PermissionError: [WinError 32]?
I don't know much about os.rename, but in fact it works some most of vedio, but it will post the error when it has only one folder left, the folder's vedios only a few can be renamed, and others can't.我不太了解os.rename,但实际上它适用于大部分vedio,但是当它只剩下一个文件夹时它会发布错误,该文件夹的vedios只有少数可以重命名,其他的则不能. What should I do?
我应该怎么办?
import os
import cv2
from moviepy.editor import VideoFileClip
import pandas as pd
class FileCheck():
def get_file_times(self, filename):
clip = VideoFileClip(filename)
file_time = self.timeConvert(clip.duration)
return file_time
def timeConvert(self, size):
M, H = 60, 60 ** 2
if size < M:
return str(size) + u's'
if size < H:
return u'%s min %s s ' % (int(size / M), int(size % M))
else:
hour = int(size / H)
mine = int(size % H / M)
second = int(size % H % M)
tim_srt = u'%s h %s min %s s ' % (hour, mine, second)
return tim_srt
def get_file_path(root_path, file_list, dir_list,deep):
dir_or_files = os.listdir(root_path)
for dir_file in dir_or_files:
dir_file_path = os.path.join(root_path, dir_file)
if os.path.isdir(dir_file_path):
dir_list.append(dir_file_path)
get_file_path(dir_file_path, file_list, dir_list,deep+1)
else:
if dir_file.find("py")!=-1 :
continue
file_list.append(dir_file_path)
if __name__ == '__main__':
df = pd.DataFrame(columns=['id','time', 'shine'])
fc = FileCheck()
root_path = r"./"
file_list = []
dir_list = []
get_file_path(root_path, file_list, dir_list,0)
#print(file_list)
s = "YJJ_"
for i in range(len(file_list)):
filename = file_list[i]
print(filename)
cap = cv2.VideoCapture(filename)
ftime = fc.get_file_times(filename)
df.loc[i] = [s+str(i), ftime, 0]
print("complete")
for i in range(len(file_list)):
filename = file_list[i]
ss = filename.split("D")[0]
os.rename(filename, ss + s + str(i)+".mov")
df.to_csv("result.csv",index=0)
I just want to calculate the time of video.我只想计算视频的时间。 But I meet
但我遇见
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D45.mov' -> 'DJI_0001.mov'
The error means that you cannot alter the chosen file because another process is using it, hence doing so might ruin/crash the other process.该错误意味着您无法更改所选文件,因为另一个进程正在使用它,因此这样做可能会破坏/崩溃另一个进程。
Make sure that the file is not open, and is not being used by another program, and try again.请确保该文件未打开,并且未被其他程序使用,然后重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.