Rename of .mdb file -- lock

N

noydb

All,

I have the code below, which unzips a zipfile containing only one
file. Once it is unzipped, I want to rename the file based on a user
provided name. But I get this (WindowsError: [Error 32] The process
cannot access the file because it is being used by another process)
error, which does not make sense to me as no other apps are open.

Any suggestions?

Thanks!

****CODE****
# Declare the zip file directory and name (shouldn't change, in a
permanent location)
mdb_zip = ("C:\\ProjWork\\mdb_geoDB_91.zip")

output_dir = ("C:\\Temp")


# ZipFile for read
z = zipfile.ZipFile(mdb_zip, 'r')
zFile = z.namelist()

# Put contents of zipfile into a list
zList = z.namelist()


# Loop thru list, write zipfile contents to new directory
for zItem in zList:
print "Unpacking",zItem
zRead = z.read(zItem)
z1File = open(os.path.join(output_dir, zItem),'wb')
z1File.write(zRead)
z1File.close
print "Finished extracting zip file"

uChoice = "test44.mdb" ## to be user chosen someday
new91mdb = os.path.join(output_dir, zItem) # C:\TEMP\GDB_9_1.mdb

##os.rename(new91mdb, (os.path.join(output_dir, uChoice)))
os.rename(new91mdb, (os.path.join(output_dir, "C:\TEMP\test1.mdb")))


del new91mdb
 
G

gudonghua+python

All,

I have the code below, which unzips a zipfile containing only one
file.  Once it is unzipped, I want to rename the file based on a user
provided name.  But I get this (WindowsError: [Error 32] The process
cannot access the file because it is being used by another process)
error, which does not make sense to me as no other apps are open.

Any suggestions?

Thanks!

****CODE****
# Declare the zip file directory and name (shouldn't change, in a
permanent location)
mdb_zip = ("C:\\ProjWork\\mdb_geoDB_91.zip")

output_dir = ("C:\\Temp")

# ZipFile for read
z = zipfile.ZipFile(mdb_zip, 'r')
zFile = z.namelist()

# Put contents of zipfile into a list
zList = z.namelist()

# Loop thru list, write zipfile contents to new directory
for zItem in zList:
    print "Unpacking",zItem
    zRead = z.read(zItem)
    z1File = open(os.path.join(output_dir, zItem),'wb')
    z1File.write(zRead)
    z1File.close
z1File.close()
 
N

noydb

I have the code below, which unzips a zipfile containing only one
file.  Once it is unzipped, I want to rename the file based on a user
provided name.  But I get this (WindowsError: [Error 32] The process
cannot access the file because it is being used by another process)
error, which does not make sense to me as no other apps are open.
Any suggestions?

****CODE****
# Declare the zip file directory and name (shouldn't change, in a
permanent location)
mdb_zip = ("C:\\ProjWork\\mdb_geoDB_91.zip")
output_dir = ("C:\\Temp")
# ZipFile for read
z = zipfile.ZipFile(mdb_zip, 'r')
zFile = z.namelist()
# Put contents of zipfile into a list
zList = z.namelist()
# Loop thru list, write zipfile contents to new directory
for zItem in zList:
    print "Unpacking",zItem
    zRead = z.read(zItem)
    z1File = open(os.path.join(output_dir, zItem),'wb')
    z1File.write(zRead)
    z1File.close

     z1File.close()


print "Finished extracting zip file"
uChoice = "test44.mdb" ## to be user chosen someday
new91mdb = os.path.join(output_dir, zItem) # C:\TEMP\GDB_9_1.mdb
##os.rename(new91mdb, (os.path.join(output_dir, uChoice)))
os.rename(new91mdb, (os.path.join(output_dir, "C:\TEMP\test1.mdb")))
del new91mdb- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Thanks! That was simple enough.

And...
##os.rename(new91mdb, (os.path.join(output_dir, uChoice)))
os.rename(new91mdb, (os.path.join(output_dir, "C:\TEMP\test1.mdb")))

.... of those two lines, the top one worked.
 
S

Steve Holden

noydb said:
On Dec 11, 9:38 pm, "(e-mail address removed)" <[email protected]>
wrote: [...]

Thanks! That was simple enough.

And...
##os.rename(new91mdb, (os.path.join(output_dir, uChoice)))
os.rename(new91mdb, (os.path.join(output_dir, "C:\TEMP\test1.mdb")))

... of those two lines, the top one worked.

The reason the second one didn't work is because "\t" is the tab
character. Look for "raw strings" in the documentation.

r"C:\TEMP\test1.mdb" should work.

regards
Steve
 
M

MRAB

Scott said:
noydb said:
I have the code below, which unzips a zipfile containing only one
file. Once it is unzipped, I want to rename the file based on a user
provided name. But I get this (WindowsError: [Error 32] The process
cannot access the file because it is being used by another process)
error, which does not make sense to me as no other apps are open.
Any suggestions?

Others have told you the reason you are currently having problems.
You should also be aware that Windows can at "random" times be opening
the new file in order to either index it or virus scan it, and it may
fail to rename during that period. So, a failure should retry in a
second a couple of times before giving up. This is my understanding,
but someone deeply familiar with Windows internals might reveal that
I am operating on older information.
It's always a good idea pause and then retry a few times, just in case.
Retrying is also a good idea when deleting a file, although in that case
you might also want to check whether the file is read-only; if it is,
then there's no point in retrying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top