WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Operations

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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
File Created: 2001:01:03:11:39:40
Last Updated: 2001:01:03:11:39:40