copy locked files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rubbishemail@web.de

    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

  • Adam Pletcher

    #2
    RE: copy locked files

    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_applicatio n\\test.dll',
    'C:\\new_folder \\test.dll')

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

    - Adam

    -----Original Message-----
    From: python-list-bounces+adam=vo lition-inc.com@python. org
    [mailto:python-list-bounces+adam=vo lition-inc.com@python. org]
    On Behalf Of rubbishemail@we b.de
    Sent: Monday, June 18, 2007 9:50 AM
    To: python-list@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

    --

    Comment

    • rubbishemail@web.de

      #3
      Re: copy locked files

      Hi Adam,



      On 18 Jun., 18:41, "Adam Pletcher" <a...@volitio n-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\te st.ncb')

      IOError: [Errno 13] Permission denied: 'C:\\a\\test\\t est.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



      Daniel

      Comment

      • Jay Loden

        #4
        Re: copy locked files



        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_applicatio n\\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

        Comment

        Working...