erase files - Resolved!!

erase files - Resolved!!

Postby Silvio.Falconi » Wed Jan 24, 2024 1:12 pm

Each time I open a Exe I Must erase some files

I tried with

Code: Select all  Expand view
if File( cdir+"cust1.dbf" )
      erase cdir+"cust1.dbf"
      erase cdir+"cust2.dbf"
      erase cdir+"cust3.dbf"
      erase cdir+"cust4.dbf"
  endif


But not erase nothing

Solution ?
Last edited by Silvio.Falconi on Fri Jan 26, 2024 11:14 am, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: erase files

Postby karinha » Wed Jan 24, 2024 1:50 pm

Code: Select all  Expand view

// C:\FWH\SAMPLES\SILVERAS.PRG

#Include "Fivewin.Ch"
#Include "Directry.ch"

FUNCTION Main()

   LOCAL cDir

   cDir := GETCURDIR()

   IF SUBS( cDir, LEN( ALLTRIM(cDir ) ) , 1 ) = "\"
      cDir := SUBS( cDir, 1 , LEN( ALLTRIM(cDir ) ) - 1 )
   ENDIF

   LCHDIR( cDir )

   // ? cDir

   IF FILE( "
CUST1.dbf" )

      FERASE("
CUST4.dbf")

      IF FILE( "
CUST4.dbf" )  // CHECK only

         ? "
Archivo Bloqueado en RED"

         QUIT

      ELSE

         ? "
Archivo deletado"

      ENDIF

      // .or.

      // AEVAL(DIRECTORY( "
CUST4.DBF" ),{ |aFILE| FERASE(aFILE[F_NAME]) } )

   ENDIF

RETURN NIL

// FIN / END


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

Re: erase files

Postby karinha » Wed Jan 24, 2024 2:26 pm

Code: Select all  Expand view

FUNCTION Main()

    LOCAL DEL_INDICE

    //-> Ideia original By Kleyber Derick
    DEL_INDICE := DIRECTORY( "*.CDX" )

    FOR I = 1 TO LEN( Del_Indice )
       FERASE( DEL_INDICE[I][1] )
    NEXT I

RETURN NIL
 


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

Re: erase files

Postby nageswaragunupudi » Wed Jan 24, 2024 2:44 pm

The command ERASE <cfile> is preprocessed as FERASE( <cfile> ).
This command or function should work (and it works for me) if the file exists and is not in use and can be deleted.

If the ERASE command does not really erase an existing file, there can be a valid reason like the file is in use by some application or some other reason.

The best way to find out the reason is to
Code: Select all  Expand view
if FERASE( cFile ) != 0
   ? FERROR()
endif

FError() tells you the reason why the file is not erased
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: erase files

Postby karinha » Wed Jan 24, 2024 3:04 pm

Very good mister Nages. Thanks.

Code: Select all  Expand view

// C:\FWH\SAMPLES\SILVERA2.PRG

#include "FiveWin.ch"
#include "fileio.ch"

FUNCTION Main()

   IF FErase( "test.txt" ) != F_ERROR

      ? "File successfully erased"

   ELSE

      ? "File can not be deleted", FERROR()

   ENDIF

RETURN NIL

// FIN / END
 


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

Re: erase files

Postby carlos vargas » Wed Jan 24, 2024 5:30 pm

Recordar que existe una función llamada hb_dbdrop la cual elimina la tabla y sus archivos de índices y memo file asociados.
hb_dbDrop([<cTable>],[<cIndex>])->Nil
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: erase files

Postby Silvio.Falconi » Wed Jan 24, 2024 7:04 pm

carlos vargas wrote:Recordar que existe una función llamada hb_dbdrop la cual elimina la tabla y sus archivos de índices y memo fil asociados.

gracias, tienes las características y parámetros de esta función? sin embargo ahora parece estar bien con "ferase"
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: erase files

Postby Rick Lipkin » Wed Jan 24, 2024 7:37 pm

Silvo

I create a local folder on the C: drive called c:\dbtmp and that is where I write all my temp files .. when the application starts it creates the folder c:\dbtmp if not alreacy exist then uses aDIr to create an array of all files in c:\dbtmp and I just use a For\Next loop of aDir and ferace the files ...

Rick Lipkin

Code: Select all  Expand view

aDIR := DIRECTORY( "C:\DBTMP\*.*", "D" )
IF EMPTY( aDIR )

   IF lMkDir( "C:\Dbtmp" )
   ELSE
      SAYING := "SORRY ... Could not make the directory "+CHR(10)
      SAYING += "C:\DBTMP needed to run this Application "+CHR(10)
      SAYING += "ABORTING"+CHR(10)
      MsgInfo( SAYING )
      IF cAUTH = 'Y'
         oDLG:End()
      ENDIF
      CLOSE DATABASES
      RETURN(.F.)
   ENDIF

ENDIF

// delete trash

FOR i = 1 to LEN( aDIR )
    cFILE := ALLTRIM( aDIR[i] [1] )
    FERASE( "C:\DBTMP\"+cFILE )
NEXT


User avatar
Rick Lipkin
 
Posts: 2617
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: erase files

Postby carlos vargas » Wed Jan 24, 2024 8:11 pm

In ct lib from harbour exist the function filedelete (you pass file name or File Mask) to delete, example: *.dbf
FileDelete(<cFileMask>,[<nAttributes>])->lDeleted
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: erase files

Postby Silvio.Falconi » Thu Jan 25, 2024 8:51 am

I made

Code: Select all  Expand view

Cancella_Archivi(".\data\")  // on Main.prg
...
return nil

Function Cancella_Archivi(cDir)
      local adir := DIRECTORY(cDir+ "
*.*", "D" )
      local i,cFile
              FOR i = 1 to LEN( aDir )
                    cFILE := ALLTRIM( aDIR[i][1] )
                    IF FErase(cDir+cFile ) != 0
                     ? FERROR()
                     endif
              NEXT
     return nil


Erased only some files ( 2 not) and the "?Ferror" give me this

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: erase files

Postby Otto » Thu Jan 25, 2024 9:12 am

In the context of Clipper and Harbour programming, the DOS error code 5, as returned by the FERROR() function, indicates "Access denied"​​. This error typically occurs when a program attempts to access a file or directory for which it does not have the necessary permissions, such as attempting to write to a read-only file, accessing a file that is locked by another process, or trying to open a file in a restricted directory.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: erase files

Postby Silvio.Falconi » Thu Jan 25, 2024 10:48 am

Otto wrote:In the context of Clipper and Harbour programming, the DOS error code 5, as returned by the FERROR() function, indicates "Access denied"​​. This error typically occurs when a program attempts to access a file or directory for which it does not have the necessary permissions, such as attempting to write to a read-only file, accessing a file that is locked by another process, or trying to open a file in a restricted directory.


Thanks Professor Otto I knew this too but it so happens that I am the administrator of the computer because it is mine and there are no restrictions, delete all the files except two, if the restriction is there why delete the other files?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: erase files

Postby Otto » Thu Jan 25, 2024 10:53 am

In use?
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: erase files

Postby Silvio.Falconi » Thu Jan 25, 2024 11:28 am

Otto wrote:In use?



???
the files

Image

Main.prg

Code: Select all  Expand view


#include "fivewin.ch"

REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN
REQUEST DBFCDX


function Main()

       RddSetDefault( "DBFCDX" )

       SetHandleCount( 100 )
       FWNumFormat( "E", .t. )

       SET DATE FORMAT "dd-mm-yyyy"
       SET DELETED     ON
       SET CENTURY     ON
       SET EPOCH TO    year( date() ) - 20
       SET MULTIPLE    OFF

         HB_LANGSELECT( "IT" )
         HB_CDPSELECT( "ITWIN" )

      Cancella_Archivi(".\data\")


DEFINE WINDOW oWnd

         @ 2,  2   BUTTON "
&App" SIZE 80, 20 ACTION Test()


     ACTIVATE WINDOW oWnd MAXIMIZED



     RETURN NIL

 static  Function Cancella_Archivi(cDir)
      local adir := DIRECTORY(cDir+ "
*.*", "D" )
      local i,cFile

              FOR i = 1 to LEN( aDir )
                    cFILE := ALLTRIM( aDIR[i][1] )
                    IF FErase(cDir+cFile ) != 0
                          Msginfo( FERROR() ,cfile)
                     endif
              NEXT
     return nil

static Function test;return nil

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: erase files

Postby Otto » Thu Jan 25, 2024 1:12 pm

Who created the cdx files. Which user account.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests