Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Checking if a File is Open or Exists

Keywords:  fileexist fileopen	Filesize==0

Question:

How can i check if a file is open or closed?

I want to import a file to another program, and the file must be closed before I import it. How can I check to see if the file is open?

Answer:

There are a couple of tricks you can use.
  1. Try FileExist. In many cases FileExist will return a 2 if the file exists but is open in read-deny mode.
    a=FileExist("yourfile")
    
    a==0 then no file.
    a==1 file exists. Looks OK.
    a==2 file exists. Not currently accessible.
    

  2. Try FileSize. If a file is open or being written to, FileSize will return a 0. File in use:
    	Filesize==0
    
Put the two of them together with:
	While !FileExist("filename")
	   TimeDelay(1)
	endwhile
	While FileSize("filename")==0
	   TimeDelay(1)
	endwhile

Article ID:   W13226
Filename:   Check if File is Open or Exists.txt