python - Getting Windows error 32 process can not access file it is used by another process -


i download podcasts have long file names , i'm stripping them have city name, date , hour (meaning first, second or third hour). seems work except os.rename(file, new_name), tells me windows can't access file.

import re, os, glob id3 import *  files in glob.glob("f:\\download\*podcasts*"):   os.chdir(files)   file in os.listdir("."):    if re.search("\a[1-3].",file):  # original filenames begin 1.,2. or 3.       tags=id3(file)       date = re.search("\w*.-\w*.-\w*.",file) # filenames contain date in mmm-dd-yyyy       date_clean = date.group(0).strip()       hour = re.search("hr\d", file)  # file names contain hr. 1,2 or 3 @ end       hour_clean = hour.group(0).strip()       tags['artist'] = "portland podcast"       tags['title'] = date_clean + hour_clean       new_name = "portland-" + date_clean + "-" + hour_clean +".mp3"       print "changing",file,"to",new_name+"."       os.rename(file,new_name)                  os.chdir("f:\\download")                              os.getcwd()                                           os.system("pause") 

something holding reference file try move. place try/except block around shutil.rename , print out file causes problem. when find out file causes problem find out holding reference it.

one way find holding reference file either using process explorer or unlocker

update:

i took @ code of id3 library , seems that, if pass in filename, doesn't close file, ever :d

you should like:

with open(filename, 'rb') f:     tags = id3(f)     # stuff shutil.rename(filename, ...) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -