05-17-2007 02:41 AM
05-17-2007 05:10 AM - edited 05-17-2007 05:10 AM
It certainly sounds as though the disc mirroring is causing the difficulty, here. For my file based applications, I always use the ANSI specified file functions (not that I don't trust the CVI ones - I just like my code to be more portable) so I'm not that familiar with the CVI versions. In particular, I might be tempted to try a fflush() call just before any fclose() - I know this should not normally be necessary but I think this action would at least enforce the correct execution sequence and ensure that there was no queue of pending OS file/mirror operations which might be confusing the situation when you try to delete the file. Is there a CVI equivalent to implement such a file flush operation? I couldn't spot one quickly.
You could always rewrite the code using ANSI calls
JR
Edit - typo!
Message Edited by jr_2005 on 05-17-2007 11:12 AM
05-18-2007 03:43 AM
03-16-2010 09:22 AM
Hi Roberto,
I know it´s not an actual problem for you, but I have the same issue at this moment.
After file operation I close the file with fclose(), then
a.) call DeleteFile() -> I get an error code -6 (access denied)
b.) call remove() -> error code -1 (access denied)
so what can I do? I can´t leave the files on the Hard drive... Did you find out, how to avoid this? Additionally, in release mode I don´t get any message, the front panel just simply closes itself.
ciao
MB
03-16-2010 03:57 PM
I am afraid I have no news for you
I remember we tried adding delays or splitting the function in two sections executed in different times, but ultimately we decided to exclude that double-copy mechanism from the application as it was not consistent and difficutl to debug.
Nevertheless, you should be able to trap the return code from the functions and handle the error, at least emitting some message.
03-17-2010 09:38 AM
Hi Roberto,
I´m not sure if it´s a solution for you, but my problem is solved!
The problem was that the function GetFirstFile() returns the filename even if the file not yet completely closed by other application - regardless which application it is. The error code -1 (access denied) I have got either at fopen() or fclose(). In my case I poll a folder, and if I see the wanted file, I open it immediately. I just inserted a Delay(0.100) prior to call fopen(), and the problem seems to be disappeared. Without this line I can reproduce the failure.
It sounds logic: each application, which saves a file, creates the file first, fills it with data, then closes it. In my case I attempted to open a file too fast, so that the file has not yet been closed by the application, which creates the file.
With the 100ms delay the failure is away. Underneath you can see my code - already with the 100ms delay.