File Deletion problem

File Deletion problem

Postby TimStone » Mon Jan 02, 2023 1: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: Select all  Expand view

    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 view

    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
TimStone
 
Posts: 2943
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: File Deletion problem

Postby jvtecheto » Mon Jan 02, 2023 8: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
User avatar
jvtecheto
 
Posts: 592
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: File Deletion problem

Postby Jimmy » Mon Jan 02, 2023 2: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
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: File Deletion problem

Postby Enrico Maria Giordano » Mon Jan 02, 2023 3: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: Select all  Expand view

    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 view

    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
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: File Deletion problem

Postby karinha » Mon Jan 02, 2023 4:15 pm

Try this:

Code: Select all  Expand view

#Include "Directry.ch"

   DELETEFILE( "FILE.TXT" )
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: File Deletion problem

Postby hua » Tue Jan 03, 2023 3: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Re: File Deletion problem RESOLVED

Postby TimStone » Tue Jan 03, 2023 7: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
User avatar
TimStone
 
Posts: 2943
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: File Deletion problem

Postby hua » Wed Jan 04, 2023 2: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 14 guests