FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour File Deletion problem
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
File Deletion problem
Posted: Mon Jan 02, 2023 01:00 AM
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 (fw): Select all Collapse
    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 (fw): Select all Collapse
    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
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: File Deletion problem
Posted: Mon Jan 02, 2023 08:55 AM

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
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: File Deletion problem
Posted: Mon Jan 02, 2023 02:23 PM
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/previous-versions/windows/it-pro/windows-7/ff686200(v=ws.10)?redirectedfrom=MSDN
FileInfoCacheLifetime
FileNotFoundCacheLifetime
DirectoryCacheLifetime
set all Value to 0 (zero) to disable "Cache"
greeting,

Jimmy
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: File Deletion problem
Posted: Mon Jan 02, 2023 03:55 PM
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 (fw): Select all Collapse
    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 (fw): Select all Collapse
    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?
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: File Deletion problem
Posted: Mon Jan 02, 2023 04:15 PM
Try this:
Code (fw): Select all Collapse
#Include "Directry.ch"

   DELETEFILE( "FILE.TXT" )
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: File Deletion problem
Posted: Tue Jan 03, 2023 03:25 AM

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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: File Deletion problem
Posted: Tue Jan 03, 2023 08:53 AM

Try also with SysWait().

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: File Deletion problem RESOLVED
Posted: Tue Jan 03, 2023 07:24 PM

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
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: File Deletion problem
Posted: Wed Jan 04, 2023 02:54 AM

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

Continue the discussion