![]() |
How to retrieve file name without path?
GetModuleFileName() function gets filename and its full path.How to retrieve file name without path?
|
Re: How to retrieve file name without path?
just chop off the path and you have it.
|
Re: How to retrieve file name without path?
how?
|
Re: How to retrieve file name without path?
get the index of the last / or \ and do a substring.
|
Re: How to retrieve file name without path?
You want the basename function. Since there is no standard implementation in C, you could use a prewritten implementation.
You generally don't want to write your own, since the format's not always so simple. There are standards, that prewritten implementations have covered. |
Re: How to retrieve file name without path?
Quote:
:
char basename[126] = {0}; |
Re: How to retrieve file name without path?
Quote:
|
Re: How to retrieve file name without path?
Quote:
Let's face it; if converting "C:\somefolder\someprogram.exe" to "program.exe" is a serious obstacle for you, then your skills aren't yet sharp enough to write a non-trivial Windows program from scratch. This isn't an insult. It's a statement of fact. Try to focus on improving what you do know, and don't assume everyone offering opinions is trying to beat you down. |
Re: How to retrieve file name without path?
Lectric, there's no indication that the OP could not accomplish that simple case in C.
He even said: "I wrote my own code but i want to learn a simple function can do same job." So he even did write it, but he wanted to know if there's something tried-and-tested he can use. Besides, there are standards for the basename of a file path. It's not always as clear-cut as "C:\somefolder\someprogram.exe" to "program.exe". Correct implementation of all standards must be followed. So the OP was correct, and rather smart, in asking about whether or not there's an existing function for this, instead of writing his own. :
|
Re: How to retrieve file name without path?
>>Besides, there are standards for the basename of a file path
Sorry, Sane, but there is no such a standard. C languages specificiations make no such statements. The links you posted earlier are only POSIX and do not apply to MS-Windows or MS-DOS. Don't know about other operating systems. So, to say there are standards is just simply misinformation. GetModuleFileName() as referenced in the OP is a MS-Windows win32 api function, not *nix. |
| All times are GMT -5. The time now is 12:46 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC