By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,114 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,114 IT Pros & Developers. It's quick & easy.

copy locked files

P: n/a
Hello,

do you know of any way to copy locked / opened files under win xp?
I know there is something like "Volume Shadow Copy" but I don't know
how to use it.
Maybe someone already has a python solution?
Many thanks
Daniel

Jun 18 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Do you mean files marked in-use by the OS, like DLLs used by an open
application?

There shouldn't be anything preventing you from copying in-use files, or
even read-only files if that's what you meant:

import shutil
shutil.copy('C:\\my_application\\test.dll',
'C:\\new_folder\\test.dll')

Although you can't move or delete an in-use file, AFAIK.

- Adam

-----Original Message-----
From: py***************************************@python.o rg
[mailto:py***************************************@p ython.org]
On Behalf Of ru**********@web.de
Sent: Monday, June 18, 2007 9:50 AM
To: py*********@python.org
Subject: copy locked files

Hello,

do you know of any way to copy locked / opened files under win xp?
I know there is something like "Volume Shadow Copy" but I
don't know how to use it.
Maybe someone already has a python solution?
Many thanks
Daniel

--
http://mail.python.org/mailman/listinfo/python-list
Jun 18 '07 #2

P: n/a
Hi Adam,

On 18 Jun., 18:41, "Adam Pletcher" <a...@volition-inc.comwrote:
Do you mean files marked in-use by the OS, like DLLs used by an open
application?
I dont know the exact name, but some programs totally lock the files,
like Visual Studio

shutil.copy('C:\\a\\test\\test.ncb','C:\\b\test.nc b')

IOError: [Errno 13] Permission denied: 'C:\\a\\test\\test.ncb'

As soon as I quit the application I can copy the file.

(I am writing a backup software which saves the changed files every
few minutes. If there was a slight possibility
to copy a file which is written at the same moment and therefore not
consistent this is still better than no backup)
>
There shouldn't be anything preventing you from copying in-use files, or
even read-only files if that's what you meant:
That's exactly my opinion!

>
Although you can't move or delete an in-use file, AFAIK.
this seems to be easier, you can use inuse.exe
http://support.microsoft.com/kb/228930/en-us
Daniel

Jun 18 '07 #3

P: n/a


Adam Pletcher wrote:
Do you mean files marked in-use by the OS, like DLLs used by an open
application?

There shouldn't be anything preventing you from copying in-use files, or
even read-only files if that's what you meant:

import shutil
shutil.copy('C:\\my_application\\test.dll',
'C:\\new_folder\\test.dll')

Although you can't move or delete an in-use file, AFAIK.
I had to deal with a similar problem using the Win32 API in C recently. You can't move or delete an in-use file, as Adam noted. However, you *can* rename a file (see http://www.nntp.perl.org/group/perl....1/msg2437.html as a nice summation of the problem), and MoveFileEx() in the Win32 API has a flag that will delete a file on the next reboot.

As far as copying an in-use file, there are two possibilities I can think of. One would be to try disconnecting the lock using the openfiles command (this may not exist on all versions of Windows, but it is there on my WinXP box). The other would be to use Locked Files Wizard (used to be called CopyLock) http://noeld.com/programs.asp?cat=misc

It comes with a command line version of the tool that you can call from your Python script as necessary. Neither is an ideal solution but I can't find any other suggestions out there on dealing with this from Python.

HTH,

-Jay
Jun 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.