locked
How to determine if "File in use" RRS feed

  • Question

  • How can I determine if a file is currently being 'used' that would prevent me from copying over the file. I would like to be able to determine who is using this file (win id). As a test i tried the following and got an error as expected:

    PS C:\src> move-item -path "main14.fmx" -destination "c:\forms" -force
    Move-Item : Cannot create a file when that file already exists.
    At line:1 char:10
    + move-item <<<<  -path "main14.fmx" -destination "c:\forms" -force
        + CategoryInfo          : WriteError: (C:\forms\main14.fmx:FileInfo) [Move-Item], IOException
        + FullyQualifiedErrorId : MoveFileInfoItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

    In my script I would like to know WHO is currently using the file; a "try...catch" scenario would only keep me from completing the copy, but I would want to know who is using the file so that I  can call USER and ask him/her to close the file so that I can copy latest version.

    Friday, March 6, 2015 10:37 PM

Answers

All replies