10-29-2009 05:20 AM
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:
Johannes
LabVIEW 7.1 (!)
10-29-2009 07:17 AM
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
10-29-2009 07:19 AM
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
10-29-2009 07:55 AM - edited 10-29-2009 07:56 AM
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.