Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check for "file in use" 1

Status
Not open for further replies.

benlrivera

Technical User
Feb 1, 2004
2
US
Hello,

I am writing a script that needs to check if a log file is in use by other user/application. Does anyone know how to do this. The way we do this now is to open the file in Word and we get the "file in use" popup box. This would help because we have alot of log files that we have to check.

Thanks
Ben
 
A solution, although it is not the only one can be seen at"

Solution provided is to use FSO and MoveFile and trap the status there.


The following may provide some help..

Also, if your not familiar with Scriptomatic, the following may help for other issues or coding snippets.



HTH
Dougc
 
Hello benlrivera,

If opening with word as a test leads to positive result, then I think using filesystemobject to open the log for appending would be equally satisfactory. Give it a try. The construction would be something like this.
Code:
logfilespec="d:\test\abc.log"    '<<<your input

set fso=createobject("scripting.filesystemobject")
on error resume next
if not fso.fileexists(logfilespec) then
    wscript.echo "The file cannot be located. Operation aborted."
    set fso=nothing : wscript.quit(1)
end if

wscript.echo "Make sure the target file is in-use. Testing will begin..."
set ots=fso.opentextfile(filespec,8,false)    'forappending
if err.number<>0 then
	 wscript.echo "file-in-used tested successfully in this case." : err.clear
else
	wscript.echo "Failed to test file-in-use."
	ots.close
end if
on error goto 0
set ots=nothing : set fso=nothing
The applicability of this scheme is limited and admittedly so. Besides, for certain cases we'll have no simple way to test 'in-use'. Notepad loads the size-limited file all to the memory for processing before saving it again. In this case, one would have a hard time to test this fact without spying the memory. But, for those cases, the fact being in-use is registered to the rot, I think it would do.

regards - tsuji
 
Thanks for the quick reply on this post. I really appreciate it. tsuji your code worked great. Thanks!! dougcranston the code that you linked to looked like more VB than VBScript sorry if I was not clear enough in my post. Thank you both for all of your help. This will save us so much time!!!

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top