Page 1 of 1

File Deletion problem

Posted: Mon Jan 02, 2023 1:00 am
by TimStone
The task is to export the contents of a file ( ewocfx ) to a .txt file, transmit the .txt file, and then delete it.

This code creates the .txt file:

Code: Select all | Expand

    DbSelectArea( 0 )
    USE (   "ewocfx" )
    COPY TO (cTxtFile) FIELDS  Eveidn, Wrkdat, Srvmil, Wrkord, Vehsta, Vehlic, Indlid, Vehmak, Vehmod, Vehyer,;
        Labcod, Labdes, Commnt, Veheng, Vehtrn, Vehsmd, Vehsty, Mlsser, Mgmsys FOR ! ewocfx->comple DELIMITED WITH PIPE
    USE
 
Then it is uploaded to the other location.

This all works perfectly.

Then I execute the following to delete the .txt file, but it doesn't go away:

Code: Select all | Expand

    FERASE( cTxtFile )
 
cTxtFile has the file name, with full drive and path location, ie. "c:\data\test.txt". It works to create, and send, the file, and it's value does not change.

Thoughts on why this would not erase the file.

Re: File Deletion problem

Posted: Mon Jan 02, 2023 8:55 am
by jvtecheto
Hi friend.

Can you try ..

Fclose (cTxtfile)

Before érase.

Regards

José

Enviado desde mi Lenovo TB-J606F mediante Tapatalk

Re: File Deletion problem

Posted: Mon Jan 02, 2023 2:23 pm
by Jimmy
hi Tim,
TimStone wrote:Thoughts on why this would not erase the file.
i guess you talk about Network using SMB-2
all Function which create a "Temporary" File will "hold" it in "Cache"

read about "SMB2 Client Redirector Caches"
https://learn.microsoft.com/en-us/previ ... dfrom=MSDN
FileInfoCacheLifetime
FileNotFoundCacheLifetime
DirectoryCacheLifetime
set all Value to 0 (zero) to disable "Cache"

Re: File Deletion problem

Posted: Mon Jan 02, 2023 3:55 pm
by Enrico Maria Giordano
TimStone wrote:The task is to export the contents of a file ( ewocfx ) to a .txt file, transmit the .txt file, and then delete it.

This code creates the .txt file:

Code: Select all | Expand

    DbSelectArea( 0 )
    USE (   "ewocfx" )
    COPY TO (cTxtFile) FIELDS  Eveidn, Wrkdat, Srvmil, Wrkord, Vehsta, Vehlic, Indlid, Vehmak, Vehmod, Vehyer,;
        Labcod, Labdes, Commnt, Veheng, Vehtrn, Vehsmd, Vehsty, Mlsser, Mgmsys FOR ! ewocfx->comple DELIMITED WITH PIPE
    USE
 
Then it is uploaded to the other location.

This all works perfectly.

Then I execute the following to delete the .txt file, but it doesn't go away:

Code: Select all | Expand

    FERASE( cTxtFile )
 
cTxtFile has the file name, with full drive and path location, ie. "c:\data\test.txt". It works to create, and send, the file, and it's value does not change.

Thoughts on why this would not erase the file.
Probably the file is still in use at the time you try to delete it. Can I see the full code from the creation of the file up to its deletion, in particular the upload section?

Re: File Deletion problem

Posted: Mon Jan 02, 2023 4:15 pm
by karinha
Try this:

Code: Select all | Expand

#Include "Directry.ch"

   DELETEFILE( "FILE.TXT" )
 
Regards, saludos.

Re: File Deletion problem

Posted: Tue Jan 03, 2023 3:25 am
by hua
A pause is required to allow windows time to finish writing and closing the text file.
I am just not sure whether one should use sysrefresh(), sleep() or some other function

Re: File Deletion problem

Posted: Tue Jan 03, 2023 8:53 am
by Enrico Maria Giordano
Try also with SysWait().

Re: File Deletion problem RESOLVED

Posted: Tue Jan 03, 2023 7:24 pm
by TimStone
Thank you. It appears I have resolved the problem.

FYI, the process is running in a service so it took time to debug since the cycle only occurs once every 24 hours.

I did implement each of the suggested options, and then found cTxtFile actually was missing the .txt extension. That was included for the upload as variable cUpFile. Switching to that, the deletion occured.

Thanks for the ideas. I have left the SysWait and FCLOSE functions in place to make the process more stable.

Re: File Deletion problem

Posted: Wed Jan 04, 2023 2:54 am
by hua
I don't think fclose() does anything since it requires a file handle, not a filename