File Name Manipulation

File Name Manipulation Functions

HB_FNameDir Extract Folder name from file specification
HB_FNameName Extract File name from file specification
HB_FNameNameExt Extract File name and extention from file specification
HB_FNameExt Extract File extention from full file specification
HB_FNameExtSet Returns changed file extension from file specification
HB_FNameMerge Composes a full file specification from individual components
HB_FNameSplit Extract folder, file, extension from full file specification

HB_FNameNameExt

HB_FNameNameExt

Extracts file name and extension portion of a file specification

Syntax

      HB_FNameNameExt( <cFileSpec>  --> <cFileNameExt>

Arguments

<cFileSpec> : a character string to extract file name and extension

Returns

<cFileNameExt> : file name and extension portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply last element of <cFileSpec>

Description

This function is used to extract file name and extension portion of a file specification string. <cFileSpec> doesn’t require include an existing file / path info.

This info can be optained by :

        cFName := ''
        cFNExt := ''
        HB_FNameSplit( cFileSpec, , @cFName, @cFNExt )
        ? cFName + cFNExt
      OR
        ? SUBSTR( cFileSpec, RAT( "\", cFileSpec ) +1 )

Example

      ? HB_FNameNameExt( "c:\temp\NewDirDB" )          // NewDirDB
      ? HB_FNameNameExt( "c:\temp\NewDirDB\test.bat" ) // test

Seealso

HB_FNameDir(), HB_FNameName(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

HB_FNameName

HB_FNameName

Extracts file name portion of a file specification

Syntax

      HB_FNameName( <cFileSpec>  --> <cFileName>

Arguments

<cFileSpec> : a character string to extract file name

Returns

<cFileName> : file name ( without extension ) portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply last element of <cFileSpec>

Description

This function is used to extract only file name from a qualified file specification string <cFileSpec> doesn’t require include an existing file / path info. This info can be optained by :

        cFName  := ''
        HB_FNameSplit( cFileSpec, , @cFName )
          ? cFName
      OR
        cNamExt := SUBSTR( cFileSpec, RAT( "\", cFileSpec ) + 1 )
         ? IF( "." $ cNamExt, LEFT( cNamExt,  RAT( ".", cNamExt ) -1 ), cNamExt )

Example

      ? HB_FNameName( "c:\temp\NewDirDB" )          // NewDirDB
      ? HB_FNameName( "c:\temp\NewDirDB\test.bat" ) // test

Seealso

HB_FNameDir(), HB_FNameNameExt(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

<

HB_FNameExtSet

HB_FNameExtSet

Change file extension part of a file specification string

Syntax

      HB_FNameExtSet( <cFileSpec>, <cNewExt>  --> <cNewFileSpec>

Arguments

<cFileSpec> : a file specification string to change file extension part

<cNewExt> : New file extension

Returns

<cNewFileSpec> : File extension changed version of <cFileSpec>

Description

This function is used to change file extension portion of a file specification string.

This can be made by :

        cFPath := ''
        cFName := ''
        HB_FNameSplit( cFileSpec, @cFPath, @cFName )
        ? cFPath + cFName + cNewExt
      OR
        ? IF( "." $ cFileSpec, LEFT( cFileSpec, RAT( ".", cFileSpec ) -1 ), 
            cFileSpec ) + cNewExt

Example

      cFileSpec := "c:\temp\test.prg"
      ? HB_FNameExtSet( cFileSpec, '.ini' )  // c:\temp\test.ini

Seealso

HB_FNameDir(), HB_FNameName(), HB_FNameNameExt(), HB_FNameExt()

HB_FNameDir

HB_FNameDir

Extracts path portion of a file specification string

Syntax

      HB_FNameDir( <cFileSpec>  --> <cFilePath>

Arguments

<cFileSpec> : a character string to extract file path

Returns

<cFilePath> : path portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply <cFileSpec> except last element <cFilePath> always include trailing OS path separator ( “\” )

Description

This function is used to extract path / dir portion of a full qualified file specification string. <cFileSpec> doesn’t require include an existing file / path info. This info can be optained by :

         HB_FNameSplit( cFileSpec, @cPath )
       OR
          ? IF( "\" $ cFileSpec, LEFT( cFileSpec, RAT( "\", cFileSpec ), 
               cFileSpec

Example

      ? HB_FNameDir( "c:\temp\NewDirDB" )          // c:\temp\
      ? HB_FNameDir( "c:\temp\NewDirDB\test.bat" ) // c:\temp\NewDirDB\

Seealso

HB_FNameName(), HB_FNameNameExt(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()