0

I am moving a file from a windows share to an ftp server by means of an application. I just want to make sure that there is indeed no other application trying to process the file as well. I tried using handle, but the program is unable to install on my work laptop. Is there a cmd command I can use to see if a certain file is being locked through an application or process?

Hendrien
  • 325
  • 1
  • 10
  • 20
  • What is `handle`? There is no `cmd` internal or Windows provided command that will reveal this. Have you looked through what is available in SysInternalsSuite`? – lit Nov 15 '16 at 14:40
  • There is no `cmd` internal or Windows provided command that will reveal this. Have you looked through what is available in SysInternals Suite`? If SysInternals will not install on your machine, that is another problem. The "application" that moves the file should have its own error handling to know if it failed. – lit Nov 15 '16 at 14:59
  • You can't move it if it's being written to by another program. So there is no need to test. See `openfiles /?` to see files opened. Note you have to turn on a special mode of windows and reboot before openfiles can work. See `openfiles /local /?`. –  Nov 15 '16 at 19:33

2 Answers2

0

Try to move the file to a temporary directory first. If this didn't fail, you may safely move the file to its final destination. Sometimes it is the ftpserver or webserver which keeps the target file open and this prevents it from being updated (somebody is downloading the file at the moment). In this case renaming of the old file may help. Operation rename works because it opens directory handle rather than the blocked file handle.

IF EXIST %TMP%\file DEL %TMP%\file
MOVE \\windows\share\file %TMP%\file
IF NOT EXIST %TMP%\file (ECHO file is not movable at the moment.&EXIT)
IF EXIST \\ftp\server\ftproot\file.bak DEL \\ftp\server\ftproot\file.bak
REN \\ftp\server\ftproot\file \\ftp\server\ftproot\file.bak
MOVE /Y %TMP%\file \\ftp\server\ftproot\file
vitsoft
  • 5,515
  • 1
  • 18
  • 31
0

I believe your answer is found here. By simply picking up on the error messages that are sent back it is quite easy to find what process is using the file or directory.

Community
  • 1
  • 1
Jake
  • 11
  • 4