11-28-2013 08:36 PM
Hi all,
One application running in other computer try to save a text file (A.txt) to a network folder, and a local labview program will copy A.txt to local drive and rename it as B.txt. Sometimes, it takes long for the A.txt to be saved to the netwrok folder and sometimes it is fast. But the labview program doesn't know when the file output is done. So it will sometimes copy the incomplete file. Is that any way to tell if the file being copied is opened by any other application so to tell when should the labview code start to copy the file? Thanks.
11-28-2013 11:08 PM - edited 11-28-2013 11:11 PM
Hi PKIM,
Please check this link: http://digital.ni.com/public.nsf/allkb/71D38BD8FCBD5BF38625763F002E82C8
And you can try the suggestion given in http://forums.ni.com/t5/LabVIEW/How-can-I-check-if-a-file-is-opened/td-p/1012382
11-28-2013 11:11 PM - edited 11-28-2013 11:28 PM
@udka wrote:
Hi PKIM,
Please check this link: http://digital.ni.com/public.nsf/allkb/71D38BD8FCBD5BF38625763F002E82C8
Thanks. I read the first article before. But that's one is about two applications both written in Labview. I try the program attached in that article, it works. For my case, the file A.txt was created and written by a third party application, I cannot control it's behavior. So does it mean there is no way to check that?
For second link, I try to open an OPENED file but it doesn't return any error. I don't know why. Does it work only when the file opened by another labview application?
By the second idea, I try the following code but doesn't work.
In one code, I try to create a file and hold for long time
In another code, I try to open the same file in OPEN mode but no error comes out
Thanks.
11-28-2013 11:34 PM
Hi PKIM,
Please find the attached vi.
I've opened simple text file with notepad and tried to open in write and read/write both modes, i got the error.Adding the screenshot also.
11-29-2013 12:01 AM
@udka wrote:
Hi PKIM,
Please find the attached vi.
I've opened simple text file with notepad and tried to open in write and read/write both modes, i got the error.Adding the screenshot also.
Hi udka,
Thanks for the reply. I try your code and I got the error also. But one thing I don't understand is you use a "Strip Path" to extract the path so I wonder if you are trying to open a folder not a file, is that why we get the error?
11-29-2013 12:53 AM
Hi PKIM,
Apologies for the mistake.Yes the error was due to strip path in that code.
I was able to reproduce the error with some effort. I got the file open error when it is opened with specific third part applications.
Instead of Notepad,tried to open with Microsft word, labview code is throwing an error.but when it's opened by normal notepad it didn't show any error.
I think it'll depend on the third party app which is using the file. can i know which other app it's using(Curious)
For the labview error code, it's sure that when error 5 occurs, it's file already open.
Ref : http://zone.ni.com/reference/en-XX/help/371361K-01/lverror/misc_lv_error_codes/
11-29-2013 01:05 AM
@udka wrote:
Hi PKIM,
Apologies for the mistake.Yes the error was due to strip path in that code.
I was able to reproduce the error with some effort. I got the file open error when it is opened with specific third part applications.
Instead of Notepad,tried to open with Microsft word, labview code is throwing an error.but when it's opened by normal notepad it didn't show any error.
I think it'll depend on the third party app which is using the file. can i know which other app it's using(Curious)
For the labview error code, it's sure that when error 5 occurs, it's file already open.
Ref : http://zone.ni.com/reference/en-XX/help/371361K-01/lverror/misc_lv_error_codes/
Thanks for your reply. Honestly, I don't know what application is it since it is not a GUI application, everything was wrapped into a DLL and dispactched to us. But I am trying to reproduce the issue buy writing a testing program with labview and labwindows. I have a labview code to open and write to a file and hold 30sec before closing. Then using your code to test it. It doesn't raise any error.
I also try to write a labwindows code in C to open and write a file for 30 sec, again, your code doesn't return any error.
So I think labview or labwindows is not opening a file exclusively.
11-29-2013 01:15 AM
11-29-2013 01:42 AM
@udka wrote:
Hi PKIM,
For Reproducing the error, please try the following.
-Create a .txt file and open it in Microsoft word.
-Now try to open the file with the code i've given.
-you should be getting an error code-5 now.
-close the word, and try re-run the code.the code shouldn't give any error.
If u want to block other apps to write to the same file, please use appropriate mode in deny access vi, and after closing the refnum, the access should be revoked.
Hi udka,
I know how to reproduce that. But what I mean is the error detecting method only works for the case that the file was opened by some application like words. It is not generally work for any 3rd application. At least not working for the case when the file was opened by my application. So this is not a completely solution I found. I am still looking for a more general method to do so 😞
11-29-2013 09:57 AM
If the other application does not open the file in a mode which excludes other simultaneous access, you will not get an error.
How often does the other application write to the file when it has it open? If you check the file size then wait a time slightly longer than the maximum write interval and check the size again, you can see if the other program is still writing. When the size stops changing, read it.
Lynn