[comp.sys.ibm.pc.programmer] splitting up filename components

chad@csd4.csd.uwm.edu (D. Chadwick Gibbons) (05/28/90)

	Take, for example, the problem of a program which accepts
a file specification as one of its parameters.  The file specification
does not necessarally have to include the current directory.  If
so, using DOS's find-first/next routines will determine if file
exists, but does not give a true file name.

	In Turbo Pascal, the FSplit takes as an argument a file
path and will return the three components of this path:  the
directory, file name, and file extension.  Does such a routine
exist in MSC?  The run-time library routines do not appear to have
such a routine.  What about a built-in DOS function?  Again, I have
checked several sources of documentation, and none appeared to have
such a routine listed.  I'm sure I could easily scan the path string
for the arguments I need and build my own routine, but I would
prefer to use any existing routines, in order to keep my code size
down to a minimum.

geiser@apollo.HP.COM (Wayne Geiser) (05/30/90)

In article <4173@uwm.edu>, chad@csd4.csd.uwm.edu (D. Chadwick Gibbons) writes:
|> 
|> 	Take, for example, the problem of a program which accepts
|> a file specification as one of its parameters.  The file specification
|> does not necessarally have to include the current directory.  If
|> so, using DOS's find-first/next routines will determine if file
|> exists, but does not give a true file name.
|> 
|> 	In Turbo Pascal, the FSplit takes as an argument a file
|> path and will return the three components of this path:  the
|> directory, file name, and file extension.  Does such a routine
|> exist in MSC?  The run-time library routines do not appear to have
|> such a routine.  What about a built-in DOS function?  Again, I have
|> checked several sources of documentation, and none appeared to have
|> such a routine listed.  I'm sure I could easily scan the path string
|> for the arguments I need and build my own routine, but I would
|> prefer to use any existing routines, in order to keep my code size
|> down to a minimum.

The runtime library does, indeed, have such a beast (At least my
version 5.0 library does).  The function that will do what you want is
_splitpath and its signature is:

void _splitpath(char *path, char *drive, char *dir, char *fname,
                char *ext)

See your Microsoft documentation for more information.

Wayne Geiser
Apollo Computer, Inc. - A subsidiary of Hewlett Packard
geiser@apollo.hp.com