LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I determine if a file exists or not on my PC?

I thought this would be an easy one and maybe I am just making it harder than what it has to be. I simply want to search in a given directory to see if a file exists on not on my hard drive. Are there any ideas as to how to do this without causing an error if the file does not exist?
0 Kudos
Message 1 of 5
(3,978 Views)
Hi:

In those situations what I've done till now is opening  the file and  close it inmediatly, if I find out and error while opening it I guess it doesn't exist. I know this is not the best way since there may be other reasons for the Open File Function to fail, but it has worked for me. Does somebody know a better way to do it?

Regards



Robst - CLD

Using LabVIEW since version 7.0


0 Kudos
Message 2 of 5
(3,967 Views)

You can check the error output of the File/Directory Info function, and if there was no error, the file does exist.  This method will not work if you're checking a path inside an LLB.  In that case, you would have to do something else, like listing the parent LLB contents and seeing if the file exists inside that parent.

I plan on including a new VI on the Advanced File I/O palette in the next version of LabVIEW that, given a file path, will return a boolean indicating if that file/folder exists...it will also work on files inside LLBs.

Hope this helps,
-D

Message 3 of 5
(3,962 Views)
The error method is easiest.  But if you can't live with producing an error, you can use the List Directory function (File I/O - Advanced File Functions).  This will output a list of files and directories in a string array format.  You can then search the array for the filename.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 5
(3,942 Views)
Alternate method:

If you know the path where you want to check the existence of the file, use the "build path" and then use "File/Directory info", and then check the error status. This will work if you know the path where you want to check.

Kudos are the best way to say thanks 🙂
0 Kudos
Message 5 of 5
(3,914 Views)