LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check if a file is opened?

Hello,

 

I have a problem:
I want to check if a file is existing or not, and if it exists, I want to check if it is opened.

 

The following actions should be taken:

1. File exists => no error message, everything's ok

2. File does not exist => NO error message, create the file later 
3. File exists but it is opened => notify user (Ok message)
4. path does not exist => notify user (Ok message)

How can I do that? I have problems to check if the file is opened.

This is what I have done until now:

 

Check_if_File_exists.PNG

 

 

 

 

 

 

 

 

 

 

 

Johannes

LabVIEW 7.1 (!)

Greetings Johannes
Using LabVIEW 7.1 and 2009 recently
0 Kudos
Message 1 of 4
(9,824 Views)

I think that if  you set the options of the open file.vi to 'Write Only' you will get an error if another process has the file open for write access as well.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 4
(9,808 Views)

You can just try to open (not "open or create") the file with r/w permissions. Based on the error you get you can decide what to do.

No error = file exists and is not open

Error 7 = file not found (doesn't exist)

Error 5 = file already open

...

 

Hope this helps,

Daniel

 

Message 3 of 4
(9,805 Views)

The error checking method is probably the best, most efficient, and cleanest way to do this (only one case structure needed). But here is a somewhat more "rube goldberg" way that does do the job thinking somewhat linearly. If the directory doesn't exist, then the file won't exist. If the file doesn't exist, then it can't be open. So first you check if the directory exists, if it does, check if the file exists, if it does check if it's open. Not a fan of these nested case structures really, but it is a way to do it.

 

Message Edited by for(imstuck) on 10-29-2009 07:56 AM
Message 4 of 4
(9,788 Views)