LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Checking for file existence in labview 6.1

I want to check if a file exist before i start writing data to it. I've tried it through swhlapi.dll with the PathFileExists function, but i get an error trying PathFileExistsA when running it the second time (when the file exists), and when i use PathFileExistsW it runs, but doesn't do the check.
0 Kudos
Message 1 of 6
(2,942 Views)
Hi,
my normal trick is to simply try to open the file and watch for error code 7 (file not found) using LV .vi's. - any reason you're using the Windows SDK for this?
I've attached the sub .vi I use.
If a valid path is entered, you'll receive a boolean for whether the file exists or not. If an error occurs (other than error 7, such as not a valid path) inside the .vi or an error condition was passed in, then you'll receive an error out as appropriate.

Hope that helps
S.
// it takes almost no time to rate an answer Smiley Wink
Message 2 of 6
(2,941 Views)
I have a successful implimentation of "PathFileExists" if you are interested. Let me know and I'll email it to you. Simply checking for an error as already suggested might be the simplest (and most platform independent) way to do this though.

john_howard@sperry-marine.com
0 Kudos
Message 3 of 6
(2,941 Views)
I only want to add, that you have open file with option "read only", because if you have permission problem and you try open with default option "read/write" you will get error also, because you can't write to file.
0 Kudos
Message 4 of 6
(2,941 Views)
Hi,

You can use File/Directory Info function (File I/O). It returns an error
(code 7) if the file does not exist.

Regards,

Wiebe.



"hvkasteren" wrote in message
news:506500000008000000D35A0000-1027480788000@exchange.ni.com...
> I want to check if a file exist before i start writing data to it.
> I've tried it through swhlapi.dll with the PathFileExists function,
> but i get an error trying PathFileExistsA when running it the second
> time (when the file exists), and when i use PathFileExistsW it runs,
> but doesn't do the check.
Message 5 of 6
(2,941 Views)
I used file/directory info to check the existence of a file.  If you create a new filename at the file open dialog box, the boolean from file/directory returned not found which is correct.  However, if i keyed in a filename that already exists in the file open dialog, the boolean also returned 'file not found' status. Has anyone come across such problem and any solution to this?  Thanks.
0 Kudos
Message 6 of 6
(2,796 Views)