Reputation: 11
I created some files by reading and modifying some original source files. I then copy the newly created files to the old filename using shutil
. When I try to delete the files created by editing the original source, i get this error:
WindowsError: [Error 32] The process cannot access the file because it is being used by another process:
I have tried opening and closing the file and pickle
for fileB in newFilesList:
#print "FileB: %s" % fileB
if re.search('newfile',fileB,flags=0):
newFileCounter+=1
fileToGo=countFiles-newFileCounter
print("There are %s files left to copy." % fileToGo)
#print "we have a match!!!!!!!!!!!!!"
os.chdir(path)
LocPreNewfile=fileB.find('newfile')
FileCBase=fileB[0:LocPreNewfile-1]
FileC= FileCBase + ".shp.iso.xml"
#print "FileCBase %s" % FileCBase
#print "FileC: %s " % FileC
os.chdir(path)
if os.path.exists(fileB):
#print "fileB %s exists!!!!!!!!!!!!!!!!!!!!!" % fileB
if os.path.exists(FileC):
#print "%s exists!!!!!!!!!!!!!!!!!!!!!" % FileC
shutil.copyfile(fileB, FileC)
if countFiles > 1:
if fileToGo >0:
os.remove(fileB)
else:
#fileD =fileB
print('One file left to remove: %s' % fileB)
else:
print ("FileC ( %s ) does not exist" % FileC)
else:
print ("%s does not exist" % fileB)
#print"---------------------------------------------------\n\n"
#print("---------------------------------------------------\n\n")
print("---------------------------------------------------\n\n")
if os.path.exists(fileB):
print("Removing %s" % fileB)
os.remove(fileB)
Upvotes: 1
Views: 180