471,342 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

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

Jun 18 '07 #1
3 5284
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
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


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.

Similar topics

8 posts views Thread by Chris Strobel | last post: by
11 posts views Thread by MarkusR | last post: by
13 posts views Thread by jim | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.