FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour erase files - Resolved!!
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
erase files - Resolved!!
Posted: Wed Jan 24, 2024 01:12 PM
Each time I open a Exe I Must erase some files

I tried with
Code (fw): Select all Collapse
 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 ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: erase files
Posted: Wed Jan 24, 2024 01:50 PM
Code (fw): Select all Collapse
// 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
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: erase files
Posted: Wed Jan 24, 2024 02:26 PM
Code (fw): Select all Collapse
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: erase files
Posted: Wed Jan 24, 2024 02: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 (fw): Select all Collapse
if FERASE( cFile ) != 0
   ? FERROR()
endif
FError() tells you the reason why the file is not erased
Regards



G. N. Rao.

Hyderabad, India
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: erase files
Posted: Wed Jan 24, 2024 03:04 PM
Very good mister Nages. Thanks.
Code (fw): Select all Collapse
// 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
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: erase files
Posted: Wed Jan 24, 2024 05: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)
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: erase files
Posted: Wed Jan 24, 2024 07: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 March-April 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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: erase files
Posted: Wed Jan 24, 2024 07: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 (fw): Select all Collapse
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
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: erase files
Posted: Wed Jan 24, 2024 08: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)
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: erase files
Posted: Thu Jan 25, 2024 08:51 AM
I made
Code (fw): Select all Collapse
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

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: erase files
Posted: Thu Jan 25, 2024 09: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.

Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: erase files
Posted: 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 March-April 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
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: erase files
Posted: Thu Jan 25, 2024 10:53 AM

In use?

Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: erase files
Posted: Thu Jan 25, 2024 11:28 AM
Otto wrote:In use?

???
the files



Main.prg
Code (fw): Select all Collapse
#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 March-April 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
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: erase files
Posted: Thu Jan 25, 2024 01:12 PM

Who created the cdx files. Which user account.