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
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
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
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