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.Put the two of them together with:
- 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.
- Try FileSize. If a file is open or being written to, FileSize will return a 0. File in use:
Filesize==0While !FileExist("filename") TimeDelay(1) endwhile While FileSize("filename")==0 TimeDelay(1) endwhile
Article ID: W13226Filename: Check if File is Open or Exists.txt