Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

copy locked files

76 views
Skip to first unread message

rubbis...@web.de

unread,
Jun 18, 2007, 10:50:24 AM6/18/07
to
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

Adam Pletcher

unread,
Jun 18, 2007, 12:41:32 PM6/18/07
to pytho...@python.org
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

> --
> http://mail.python.org/mailman/listinfo/python-list
>

rubbis...@web.de

unread,
Jun 18, 2007, 1:05:56 PM6/18/07
to
Hi Adam,

On 18 Jun., 18:41, "Adam Pletcher" <a...@volition-inc.com> wrote:
> 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.ncb')

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

Jay Loden

unread,
Jun 18, 2007, 1:45:25 PM6/18/07
to pytho...@python.org

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.makemaker/2006/01/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

corey...@gmail.com

unread,
Aug 31, 2017, 3:19:02 AM8/31/17
to
No please! I have tried using shadow copy but hell no it didn't worked at all, even hangs multiple times. I don't know much about python but I am currently using GS Richcopy 360 to solve this issue. Its a GUI based software, a paid one not to mention. But its worth every single penny. I have been using it for a year now and it never disappoints me.

Steven D'Aprano

unread,
Aug 31, 2017, 3:29:53 AM8/31/17
to
On Thu, 31 Aug 2017 00:18:39 -0700, coreylean1 wrote:

> On Monday, June 18, 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^


> No please! I have tried using shadow copy


You are replying to a ten year old message. I very much doubt the
original poster (or anyone else for that matter) still cares. They're
either already solved the problem, or moved on.




--
Steven D'Aprano
“You are deluded if you think software engineers who can't write
operating systems or applications without security holes, can write
virtualization layers without security holes.” —Theo de Raadt
0 new messages