LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I check/query whether a file is in use/locked by another program?

My data acqusition system writes data files that some users would like to inspect while the acquisition is still running. I periodically write to the file and then close the files afterwards. However, if the user opens the data file in e.g. Excel, the file is locked. This is not a problem, in the sense that I can just postpone the commitment of data to the disk, but instead of getting an error message, I would like to be able to check whether the file is locked before attempting to write it.
0 Kudos
Message 1 of 3
(3,144 Views)
Getting the error should be pretty quick when you attempt to write. I mention this because there should be no performace problems with using the code you already have. Instead, I think you should condisider ancy error handling. Right after file open you can unbundle the error cluster and inspect the error code. This error code can then be sent to a case struture for conditional logic. Remember you can always rebundle the error cluster with any data you want after you have trapped the file lock error.
0 Kudos
Message 2 of 3
(3,144 Views)
Another option you may want to consider. You can require the user to open the data file as Read-Only. If the user opens Excel, browses for the file and chooses Open as Read Only, the problem is eliminated.

What I like to do is include a button on the front panel that will open the data file for them, allowing me to force it to be read only. There are two easy ways to do this:

1. Elegant: ActiveX. Open Excel.app, make visible, workbooks.open with read only true. Close all references.

2. Quick: SystemExec. Call the command line >Excel.exe d:\Data\flowdata.xls /r

Michael
www.abcdefirm.com
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 3 of 3
(3,144 Views)