locked
Verify if Files are Open before Moving Folder in Network RRS feed

  • Question

  • I'm trying to create a script, either by Powershell or CMD to verify if any files are open in a particular network folder.   If there is a file Open then "File is in Use by NameOfUser" else it will copy folder.  If No errors, then will delete old folder from previous location.  Hate to Move files and if there is an error it causes to many issues.  This way if it copies successfully then it will delete successfully. 
    Saturday, January 24, 2015 7:12 PM

Answers

  • Use robocopy and tell it to retry only once on a failed copy (/r:1). Robocopy can also move files (/mov).

    This forum, however, is not a support forum for robocopy (other than providing general guidance like the above).

    You can find the documentation for robocopy by doing a quick web search for "robocopy documentation".


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Sunday, January 25, 2015 3:23 PM
    • Marked as answer by Bill_Stewart Wednesday, March 4, 2015 6:04 PM
    Saturday, January 24, 2015 7:18 PM

All replies

  • Use robocopy and tell it to retry only once on a failed copy (/r:1). Robocopy can also move files (/mov).

    This forum, however, is not a support forum for robocopy (other than providing general guidance like the above).

    You can find the documentation for robocopy by doing a quick web search for "robocopy documentation".


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Sunday, January 25, 2015 3:23 PM
    • Marked as answer by Bill_Stewart Wednesday, March 4, 2015 6:04 PM
    Saturday, January 24, 2015 7:18 PM
  • Outside of RoboCopy there is no way to track open files without altering the global flags.  This requires a reboot and also adds much extra overhead.

    There are bery low-level APIs that can walk the handles in the system and look for files that are open.  This is also computer intensive.

    Use RoboCopy.


    ¯\_(ツ)_/¯

    Saturday, January 24, 2015 8:02 PM
  • Thanks, I'll look into this on Monday
    Sunday, January 25, 2015 5:48 PM