|
Answer» Hi all,
Can anyone suggest me whether its possible to write a batch to check whether a file is completely written or in the process of writing. filecheck.bat path\filename should tell whether that file is completely written or in progress.
Thanks in advanceI am unsure if this is possible in batch, but I know I could definitely do it in VB. If you want me to build it for you, feel free to PM me.Yes it is possible. You cannot rename a file which is in USE by another process, so all you have to do is test if the file exists and then ATTEMPT to rename the file to a dummy name (which does not exist). If the errorlevel is greater than 0 then the file is in use by another process and you cannot rename it. If the errorlevel is zero then the rename succeeded so you rename it back again to its real name. Of course we assume that other sources of error are taken care of e.g. read-only medium, dummy file already exists, etc.
Thanks both.
Bob can u help me in PROVIDING the vb script.
To clarify, I spoke of Visual Basic, not the Scripting variant of such. I could certainly help you if you wish. I just need about three days, because I don't have constant computer access.batch
Code: [Select]echo off echo Testing file %~nx1 if not exist "%~dpnx1" echo File does not exist! & goto END if exist "%~dp1\dummy.file" del "%~dp1\dummy.file" ren "%~dpnx1" dummy.file If %Errorlevel% gtr 0 ( echo file in use ) else ( echo file not in use ren "%~dp1\dummy.file" "%~nx1" ) :end VBscript
Code: [Select]filespec=wscript.arguments(0) set fso=createobject("scripting.filesystemobject") on error resume next if not fso.fileexists(filespec) then wscript.echo "File does not exist!" set fso=nothing : wscript.quit(1) end if
wscript.echo "Testing file " & Filespec set ots=fso.opentextfile(filespec,8,false) 'forappending if err.number<>0 then wscript.echo "file in use" : err.clear else wscript.echo "file not in use" ots.close end if on error goto 0 set ots=nothing : set fso=nothing Never mind VB. Thank you, Salmon Trout.Thanks salman trout.I am thinking you could probably do this also with the OPENFILES command or the HANDLE Utility. http://technet.microsoft.com/en-us/sysinternals/bb896655
|