Page 1 of 2

erase files - Resolved!!

PostPosted: Wed Jan 24, 2024 1:12 pm
by Silvio.Falconi
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 ?

Re: erase files

PostPosted: Wed Jan 24, 2024 1:50 pm
by karinha
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.

Re: erase files

PostPosted: Wed Jan 24, 2024 2:26 pm
by karinha
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.

Re: erase files

PostPosted: Wed Jan 24, 2024 2:44 pm
by nageswaragunupudi
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

Re: erase files

PostPosted: Wed Jan 24, 2024 3:04 pm
by karinha
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.

Re: erase files

PostPosted: Wed Jan 24, 2024 5:30 pm
by carlos vargas
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

Re: erase files

PostPosted: Wed Jan 24, 2024 7:04 pm
by Silvio.Falconi
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"

Re: erase files

PostPosted: Wed Jan 24, 2024 7:37 pm
by Rick Lipkin
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



Re: erase files

PostPosted: Wed Jan 24, 2024 8:11 pm
by carlos vargas
In ct lib from harbour exist the function filedelete (you pass file name or File Mask) to delete, example: *.dbf
FileDelete(<cFileMask>,[<nAttributes>])->lDeleted

Re: erase files

PostPosted: Thu Jan 25, 2024 8:51 am
by Silvio.Falconi
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

Re: erase files

PostPosted: Thu Jan 25, 2024 9:12 am
by Otto
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.

Re: erase files

PostPosted: Thu Jan 25, 2024 10:48 am
by Silvio.Falconi
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?

Re: erase files

PostPosted: Thu Jan 25, 2024 10:53 am
by Otto
In use?

Re: erase files

PostPosted: Thu Jan 25, 2024 11:28 am
by Silvio.Falconi
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


Re: erase files

PostPosted: Thu Jan 25, 2024 1:12 pm
by Otto
Who created the cdx files. Which user account.