File Deletion problem

Post Reply
User avatar
TimStone
Posts: 2951
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

File Deletion problem

Post 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.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
jvtecheto
Posts: 603
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: File Deletion problem

Post by jvtecheto »

Hi friend.

Can you try ..

Fclose (cTxtfile)

Before érase.

Regards

José

Enviado desde mi Lenovo TB-J606F mediante Tapatalk
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: File Deletion problem

Post 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"
greeting,
Jimmy
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: File Deletion problem

Post 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?
User avatar
karinha
Posts: 7885
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: File Deletion problem

Post by karinha »

Try this:

Code: Select all | Expand

#Include "Directry.ch"

   DELETEFILE( "FILE.TXT" )
 
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
hua
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: File Deletion problem

Post 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
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
User avatar
TimStone
Posts: 2951
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: File Deletion problem RESOLVED

Post 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.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
hua
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: File Deletion problem

Post by hua »

I don't think fclose() does anything since it requires a file handle, not a filename
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
Post Reply