DELETE FILE

DELETE FILE

Remove a file from disk

Syntax

      DELETE FILE <xcFile>

Arguments

<xcFile> Name of file to remove

Description

This command removes a file from the disk. The use of a drive, directo- ry, and wild-card skeleton operator is allowed for the root of the filename. The file extension is required. The SET DEFAULT and SET PATH commands do not affect this command.

The file must be considered closed by the operating system before it may be deleted.

Examples

      DELETE FILE C:\temp\read.txt

Compliance

Clipper

Seealso

CURDIR(), FILE(), FERASE(), ERASE

CurDir()

 

CURDIR()

Returns the current OS directory name.

Syntax

      CURDIR( [<cDrive>] )  --> cPath

Arguments

<cDrive> OS drive letter

Returns

<cPath> Name of directory

Description

This function yields the name of the current OS directory on a specified drive. If <cDrive> is not specified, the currently logged drive will be used.

This function should not return the leading and trailing (back)slashes.

If an error has been detected by the function, or the current OS directory is the root, the value of the function will be a NULL byte.

Examples

      ? Curdir()

Compliance

Clipper

Platforms

All

Files

Library is rtl

Seealso

FILE()

HB_DiskSpace()

HB_DISKSPACE()

Get the amount of space available on a disk

Syntax

      HB_DISKSPACE( [<cDrive>] [, <nType>] ) --> nDiskbytes

Arguments

<cDrive> The drive letter you are requesting info on. The default is A:

<nType> The type of space being requested. The default is HB_DISK_AVAIL.

Returns

<nDiskBytes> The number of bytes on the requested disk that match the requested type.

Description

By default, this function will return the number of bytes of free space on the current drive that is available to the user requesting the information.

There are 4 types of information available:

HB_FS_AVAIL The amount of space available to the user making the request. This value could be less than HB_FS_FREE if disk quotas are supported by the O/S in use at runtime, and disk quotas are in effect. Otherwise, the value will be equal to that returned for HB_FS_FREE.

HB_FS_FREE The actual amount of free diskspace on the drive.

HB_FS_USED The number of bytes in use on the disk.

HB_FS_TOTAL The total amount of space allocated for the user if disk quotas are in effect, otherwise, the actual size of the drive.

If information is requested on a disk that is not available, a runtime error 2018 will be raised.

Examples

      #include "fileio.ch"
      ? "You can use : " + hb_ntos( hb_DiskSpace() ) + " bytes " +;
        "Out of a total of " + hb_ntos( hb_DiskSpace( "C:", HB_FS_TOTAL ) )

      Note: See tests\tstdspac.prg for another example

Compliance

Harbour

Platforms

DOS, Win, OS2, Unix

Files

Library is rtl Header is fileio.ch

DiskSpace()

DISKSPACE()

Get the amount of space available on a disk

Syntax

      DISKSPACE( [<nDrive>] ) --> nDiskbytes

Arguments

<nDrive> The number of the drive you are requesting info on where 1 = A, 2 = B, etc. For 0 or no parameter, DiskSpace will operate on the current drive. The default is 0

Returns

<nDiskBytes> The number of bytes on the requested disk that match the requested type.

Description

By default, this function will return the number of bytes of free space on the current drive that is available to the user requesting the information.

If information is requested on a disk that is not available, a runtime error 2018 will be raised.

Examples

      ? "You can use : " + hb_ntos( DiskSpace() ) + " bytes "

      Note: See tests\tstdspac.prg for another example

Compliance

Clipper

Platforms

DOS, Win, OS2

Files

Library is rtl Header is fileio.ch

SP_CDIR

 CDIR() Change Directory

 Returns
 <lSuccess> => Success or not

 Syntax
 CDIR(<cPath>)

 Description
 Attempts to change directory to <cPath> - a valid
 directory on the current drive.

 Examples

  IF CDIR("\OVERTHERE")
    MSG("We're over there now")
  ENDIF

 Source: CDD.ASM

 

SP_FULLDIR

FULLDIR()

  Short:
  ------
  FULLDIR() Interactively navigate directories

  Returns:
  --------
  <lSelected> => Directory was selected

  Syntax:
  -------
  FULLDIR([lChange],[@cDirName])

  Description:
  ------------
  Interactively navigates directories on the current
  drive.

  Allows reading of a file ( with FILEREAD() ) in a
  directory.

  If file is DBF, does a DBEDIT browse (watch your
  memory..)

  [lChange]    True - change to selected directory
               False - don't change to selected directory
               Default is True - change

  [@cDirName] Char string passed by reference, will
  contain name of selected directory on return.

  Examples:
  ---------
   cNewDir := ""

   if FULLDIR(.F.,@cNewDir)
       SET DEFAULT TO (cNewDir)
       ?"New directory is:"
       ?Curdir()
   endif

   if FULLDIR(.t.)
       ?"New directory is:"
       ?Curdir()
   endif

  Source:
  -------
  S_FULLD.PRG

 

C5_DIRCHANGE

 DIRCHANGE()
 Change the current DOS directory
------------------------------------------------------------------------------
 Syntax

     DIRCHANGE(<cDir>) --> nSuccess

 Arguments

     <cDir> is the name of the directory to change to, including the
     drive.

 Returns

     DIRCHANGE() returns 0 if successful; -1 if there is an argument error.
     Otherwise, DIRCHANGE() returns the DOS error code.

 Description

     DIRCHANGE() changes the current DOS directory.  This function may also
     be used to determine whether or not a directory exists.

 Examples

     .  The following example attempts to change to the "c:\dos"
        directory.  If it is unsuccessful, an error message is displayed.

        nResult :=  DIRCHANGE("c:\dos")

        IF nResult != 0
           ? "Cannot change directory. "
           DO CASE
              CASE nResult == 3
                 ?? "Directory does not exist."
              CASE nResult == 5
                 ?? "Access to directory denied."
           END
           BREAK
        ENDIF

       You may also use something like this:

        DIRCHANGE( "..\..\test" )

 Files   Library is EXTEND.LIB.

See Also: CURDIR(), DIR*, DIRMAKE(), DIRREMOVE(), DIRCHANGE()

C5_CURDIR

 CURDIR()
 Return the current DOS directory
------------------------------------------------------------------------------
 Syntax

     CURDIR([<cDrivespec>]) --> cDirectory

 Arguments

     <cDrivespec> specifies the letter of the disk drive to query.  If
     not specified, the default is the current DOS drive.

 Returns

     CURDIR() returns the current DOS directory of the drive specified by
     <cDrivespec> as a character string without either leading or trailing
     backslash (\) characters.

     If an error occurs, or the current directory of the specified drive is
     the root directory, CURDIR() returns a null string ("").

 Description

     CURDIR() is an environment function that gives you the name of the
     current DOS directory, ignoring the SET DEFAULT and SET PATH settings.

 Examples

     .  These examples illustrate various CURDIR() results:

        ? CURDIR("E:")     // Result: null string--root directory
        ? CURDIR("C")      // Result: CLIP53\SOURCE
        ? CURDIR("C:")     // Result: CLIP53\SOURCE
        ? CURDIR()         // Result: null string--root directory
        ? CURDIR("A")      // Result: null string--drive not ready

     .  This example changes the current DOS directory to a new value
        if it does not match a specified directory:

        IF CURDIR("C:") != "CLIP53\SOURCE"
           RUN CD \CLIP53\SOURCE
        ENDIF

 Files   Library is EXTEND.LIB, source file is SOURCE\SAMPLE\EXAMPLEA.ASM

See Also: FILE()

DIRCHANGE() Function

DIRCHANGE() Function Sample

/*
DIRCHANGE()

    Change the current DOS directory

Syntax :

DIRCHANGE( <cDir> ) –> nSuccess

Arguments :

<cDir> is the name of the directory to change to, including the drive.

Returns :

   DIRCHANGE() returns 0 if successful; -1 if there is an argument error. Otherwise, DIRCHANGE() returns the DOS error code.

Description :

  DIRCHANGE() changes the current DOS directory. This function may also be used to determine whether or not a directory exists.

Examples :

  The following example attempts to change to the “c:\dos” directory. If it is unsuccessful, an error message is displayed.

 nResult := DIRCHANGE("c:\dos")
 IF nResult != 0
    ? "Cannot change directory. "
    DO CASE
      CASE nResult == 3
         ?? "Directory does not exist."
      CASE nResult == 5
         ?? "Access to directory denied."
    ENDCASE
    BREAK
 ENDIF

 You may also use something like this:
 DIRCHANGE( "..\..\test" )

 Remarks :

    If <cDir> includs drive specifier, DIRCHANGE() also changes the current drive.

*/

PROC DirChTest()
    LOCAL cDirToChange := "c:\harbour"

    LOCAL cCurDrive := DISKNAME()

    LOCAL nResult

    ? "Current Drive is :", cCurDrive

    nResult := DIRCHANGE( cDirToChange )
    IF nResult = 0
       cCurDrive := DISKNAME()
       ? "Current directory of drive", cCurDrive, "changed to :", CURDIR()
    ELSE
       ? "Cannot change directory to", cDirToChange, ": "
       DO CASE
          CASE nResult = 2
             ?? "File does not exist."
          CASE nResult = 3
             ?? "Directory does not exist."
          CASE nResult = 5
             ?? "Access to directory denied."
          CASE nResult = 15
             ?? "Invalid Drive was specified."
          CASE nResult = 21
             ?? "Drive not ready." 
          OTHE 
             ?? "Unknown error !", nResult
       ENDCASE
    ENDIF

    // Inspect dir existence :
    cDirToChange := "C:\TEMP"
    ? DISKNAME() + ":\" + CURDIR()
    ? cDirToChange, "directory is", IF( IsThisADir( cDirToChange ),;
                                        "", "not" ), "exists." 
    ? DISKNAME() + ":\" + CURDIR()
    ?
    WAIT "End of DIRCHANGE.PRG"

RETU // DirChTest()

/*
 Using DIRCHANGE() function to determine whether or not a directory exists.
*/

FUNC IsThisADir( cDirSpec )
   LOCAL cCurrent := DISKNAME() + "\" + CURDIR(),;
         lRetval := .F.

   IF !EMPTY( cDirSpec )
      lRetval := ( DIRCHANGE( cDirSpec ) = 0 )
      DIRCHANGE( cCurrent )
   ENDIF

RETU lRetval // IsThisADir()

C5 File Management

C5 File Management Commands and Functions

High Level :

ADIR()* :

Fill a series of arrays with directory information

ADIR( [ <cFilespec> ],
    [ <aFilenames> ],
    [ <aSizes> ],
    [ <aDates> ],
    [ <aTimes> ],
    [ <aAttributes> ] ) --> nFiles

CLOSE :

Close a specific set of files

CLOSE [ <idAlias> | ALL | ALTERNATE | DATABASES | FORMAT |INDEXES ]

COPY FILE :

Copy a file to a new file

COPY FILE <xcSourceFile> TO <xcTargetFile> | <xcDevice>

CURDIR() :

Return the current DOS directory

CURDIR( [ <cDrivespec> ] ) --> cDirectory

DELETE FILE :

Remove a file from disk

DELETE FILE | ERASE <xcFile>

DIR* :

Display a listing of files from a specified path

DIR [ <xcFileSpec> ]

        DIRCHANGE() :

      Change the current DOS directory

       DIRCHANGE(<cDir>) --> nSuccess

DIRECTORY() :

Create an array of directory and file information

DIRECTORY( <cDirSpec>, [ <cAttributes> ] ) --> aDirectory

 DIRMAKE()

         Create a directory

        DIRMAKE(<cNewDir>) --> nSuccess

          DIRREMOVE() :

     Remove a directory

       DIRREMOVE(<cDirName>) --> nSuccess

          DISKCHANGE() :

       Change the current DOS disk drive

        DISKCHANGE(<cDrive>) --> lSuccess

          DISKNAME() :

                  Return the current DOS drive

        DISKNAME() --> cDrive

DISKSPACE() :

Return the space available on a specified disk

DISKSPACE( [ <nDrive> ] ) --> nBytes

ERASE :

Remove a file from disk

ERASE | DELETE FILE <xcFile>

FILE() :

Determine if files exist in the default directory or path

FILE( <cFilespec> ) --> lExists

RENAME :

Change the name of a file

RENAME <xcOldFile> TO <xcNewFile>

SET ALTERNATE :

Echo console output to a text file

SET ALTERNATE TO [ <xcFile> [ADDITIVE]]
SET ALTERNATE on | OFF | <xlToggle>

SET DEFAULT :

Set the CA-Clipper default drive and directory

SET DEFAULT TO [ <xcPathspec> ]

SET PATH :

Specify the CA-Clipper search path for opening files

SET PATH TO [ <xcPathspec list> ]

TYPE :

Display the contents of a text file

TYPE <xcFile> [TO PRINTER] [TO FILE <xcOutFile> ]

Low-level :

FCLOSE() :

Close an open binary file and write DOS buffers to disk

FCLOSE( <nHandle> ) --> lError

FCREATE() :

Create and/or truncate a binary file to zero length

FCREATE( <cFile>, [ <nAttribute> ] ) --> nHandle

FERASE() :

Delete a file from disk

FERASE( <cFile> ) --> nSuccess

FERROR() :

Test for errors after a binary file operation

FERROR() --> nErrorCode

FOPEN() :

Open a binary file

FOPEN( <cFile>, [ <nMode> ] ) --> nHandle

FREAD() :

Read characters from a binary file into a buffer variable

FREAD( <nHandle>, @<cBufferVar>, <nBytes> ) --> nBytes

FREADSTR() :

Read characters from a binary file

FREADSTR( <nHandle>, <nBytes> ) --> cString

          FRENAME() :

Change the name of a file

       FRENAME( <cOldFile>, <cNewFile> ) --> nSuccess

FSEEK() :

Set a binary file pointer to a new position

FSEEK( <nHandle>, <nOffset>, [ <nOrigin> ] ) --> nPosition

FWRITE() :

Write to an open binary file

FWRITE( <nHandle>, <cBuffer>, [ <nBytes> ] )
    --> nBytesWritten

HEADER() :

Return the current database file header length

HEADER() --> nBytes