Extracting path and file name and extension

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Extracting path and file name and extension

Post by serge_girard »

Hi there,

I forgot the names of some file functions....

I have eg. C:\path1\path2\filename.ext and I need :

Path -->C:\path1\path2
Filename (wo extension) -->filename
Extension ->EXT

Which function can help me?

Serge
There's nothing you can do that can't be done...
User avatar
gfilatov
Posts: 1090
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Extracting path and file name and extension

Post by gfilatov »

serge_girard wrote: Sat Jun 17, 2023 4:25 pm Hi there,

I forgot the names of some file functions....

I have eg. C:\path1\path2\filename.ext and I need :

Path -->C:\path1\path2
Filename (wo extension) -->filename
Extension ->EXT

Which function can help me?
Hey Serge,

Try the following useful functions: :arrow:

Code: Select all

*-----------------------------------------------------------------------------*
FUNCTION cFilePath ( cPathMask )
*-----------------------------------------------------------------------------*
   LOCAL cPath

   hb_FNameSplit ( cPathMask, @cPath )

RETURN hb_StrShrink( cPath )

*-----------------------------------------------------------------------------*
FUNCTION cFileName ( cPathMask )
*-----------------------------------------------------------------------------*
   LOCAL cName

   hb_FNameSplit ( cPathMask, , @cName )

RETURN ( cName )

*-----------------------------------------------------------------------------*
FUNCTION cFileExt ( cPathMask )
*-----------------------------------------------------------------------------*
   LOCAL cExt

   hb_FNameSplit ( cPathMask, , , @cExt )

RETURN cExt

Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Extracting path and file name and extension

Post by edk »

Look at https://github.com/Petewg/harbour-core/wiki/File-IO
hb_FNameDir(<cFileName>)
hb_FNameExt(<cFileName>)
hb_FNameName(<cFileName>)
hb_FNameNameExt(<cFileName>)
hb_FNameSplit(<cFileName>, [@cFullPathWithDrive], [@cName], [@cExt], [@cDriveLetter])
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Extracting path and file name and extension

Post by serge_girard »

Thanks Edward+Grigory !

Serge
There's nothing you can do that can't be done...
Post Reply