开发者

Bat file MOVE fails due to other process handle

I have a bat file as part of larger maintenance system that runs on a nightly basis, performs a bit of housekeeping, SVN updating etc. Part of this involves moving/deleting files, however, occasionally this fails due to another process not releasing a handle on the files/dirs to be moved. Is there any way to force the BAT file to override any existing handles and continue with the MOVE? I can only think of a look up method using ProcessExplorer/Assassin - although I'm not sure that would even work. Alternatively a "sleep开发者_StackOverflow中文版" and then reattempt if it failed the first time, although that would be a matter of luck than solving the underlying problem. Any ideas/suggestions much appreciated. Thanks.


Robocopy has a move function, and can wait on error


Here are a few things that I have done in similar situations:

  • Before the move command, ensure that other script threads CD out of the target directory.
  • Use robocopy (from the Resource Kits) with options like retry /r:3 and wait /w:5.
  • Script the first action as COPY so the script can continue working, then later in the script do the deletion at the old/unneeded location.
  • As you've already mentioned, create a little retry loop using IF ERRORLEVEL commands to test the success of the MOVE command.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜