Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, Does anybody know how a get

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi,

Does anybody know how a get the file name from a string with file and path ?

Ex:

C:\test\file.dat

I would like to have only the file name: file.dat

Thanks
 
Try this function

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

which is prototyped in stdlib.h / cstdlib

/JOlesen
 
I have a subroutine that does this. Of course, I got this somewhere else, but I don't remember where.

const char * GetFileName(const char *pszPathName )
{
static CString STmp = pszPathName;
STmp.MakeReverse();
STmp = STmp.SpanExcluding("\\");
STmp.MakeReverse();
return STmp;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top