ni.com is experiencing intermittent service disruptions.

Support teams are actively working on the resolution.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do i check if a file exists ?

Hi
 
Is it possible to check if a file (not a vi)  that I have created in my application exists or not?
 
Thank you.
0 Kudos
Message 1 of 9
(13,581 Views)
1... Use GET FILE INFO and look at the error returned. If it returns a FILE NOT FOUND error, that means it does not exist. If it returns NO ERROR, the file does exist.

2... Open the file for reading, then close it. If you get a FILE NOT FOUND error....

3... Do a LIST FILES for the directory in question, and search the returnedd list for the file you want.

All of these assume you know where the file should be, if it does exist.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 9
(13,574 Views)
This  works for me.  I made it insensitive to case as well.

0 Kudos
Message 3 of 9
(13,531 Views)
FYI,
 
several vis don't work with UNC paths (unless the UNC path is also mounted as a drive path),
the vis I used in this example (Get Permissions and File/Directory info) do work with UNC paths.
the Get Permissions vi is about 1 tickcount faster than the File/Directory info vi on average.
 
I tested it with a Novell mounted volume, 8 levels deep on 2700 files.
Get Permissions averages to 1.8ms
File/Directory Info averages to 2.8ms 
0 Kudos
Message 4 of 9
(13,258 Views)

For other searchers out there:

 

in LabVIEW 2010 there is a Check if File or Folder Exists.vi 

It is found under the functions palette  Programming - File I/O - Adv File Functions

 

Not sure if this has UNC functionality.

Message 5 of 9
(12,825 Views)

 


@wildcatherder wrote:

For other searchers out there:

 

in LabVIEW 2010 there is a Check if File or Folder Exists.vi 

It is found under the functions palette  Programming - File I/O - Adv File Functions

 

Not sure if this has UNC functionality.


This is available at least as early as 8.6

 

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 6 of 9
(12,819 Views)

Post has been dead for a few years so I will ask a question of my own, for the sake of not creating more threads on the discussion boards. Hope this is okay with the Original Post Author an everyone else. I have a system going that checks if a file already exists, if it does then it prompts the user to enter the time and date and appends that to the path. However, the group I work with would like it so that if the file already exists it will simply add a "_1" or "_2" etc. 

I imagine I would take the file name, create a substring with only the file name and not all of the directories, and append a string with the "_number" to it. This sounds time consuming and somewhat inneffficient. Does anyone know of a better way to do it? Thanks a ton in advance!

0 Kudos
Message 7 of 9
(12,404 Views)

There is no advantage to tacking a different question onto an old thread.  I strongly suggest you re-post as a new thread.

0 Kudos
Message 8 of 9
(12,401 Views)

Agreed about the new thread.

However, you don't need to do much for your problem. Just use one "Strip Path", change the string, then "Join Path".

0 Kudos
Message 9 of 9
(12,381 Views)