![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() |
Re: How to retrieve file name without path?
Okay, so I guess not "standards", but someone has already gone to the trouble for you to lay out how a basename function should perform. I can't come up with any better word.
My point was implementations already exist that follow this laid out procedure. |
|
|
|
|
|
#12 |
|
Newbie
Join Date: Apr 2008
Posts: 15
Rep Power: 0
![]() |
Re: How to retrieve file name without path?
thank you SANE for explaining what i try to imply
|
|
|
|
|
|
#13 |
|
Newbie
Join Date: Apr 2008
Posts: 15
Rep Power: 0
![]() |
Re: How to retrieve file name without path?
Sane you are right there is a standart
PathStripPath: http://msdn.microsoft.com/en-us/libr...56(VS.85).aspx |
|
|
|
|
|
#14 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 551
Rep Power: 4
![]() |
Re: How to retrieve file name without path?
Quote:
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
|
|
|
|
|
|
#15 |
|
Newbie
Join Date: Apr 2008
Posts: 15
Rep Power: 0
![]() |
Maybe it is not for *nix etc. But it is a standart for windows and i asked for windows.but i dont want to argue with you again.you are a billion times more better than me
![]() |
|
|
|
|
|
#16 |
|
Newbie
Join Date: Jul 2008
Posts: 8
Rep Power: 0
![]() |
Re: How to retrieve file name without path?
The easiest way is to start from the back of the string and search for the "\\". This is easy. Once you have the pointer you can display the file name.
int len = strlen(fname);
int pos = len - 1;
char* name = NULL;
while (pos >= 0)
{
if (fname[pos] == '\\')
{
pos++;
name = fname + pos;
printf("fname=%s\n", name);
}
pos--;
} |
|
|
|
|
|
#17 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 551
Rep Power: 4
![]() |
Re: How to retrieve file name without path?
Sorry, but I disagree. The easiest way it to use strrchr() so that you don't have to reinvent the wheel.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
|
|
|
|
|
#18 |
|
Newbie
Join Date: Jul 2008
Posts: 8
Rep Power: 0
![]() |
Re: How to retrieve file name without path?
Yeah, but you have to check to see if the pointer is valid. It is easier to look at each character directly. Anyways, either way can work. My way might be a bit quicker, though. We don't all have to agree.
|
|
|
|
|
|
#19 |
|
Newbie
Join Date: Sep 2008
Posts: 3
Rep Power: 0
![]() |
Re: How to retrieve file name without path?
There is also a _splitpath function, that can help in the OP problem, and some more similar ones.
|
|
|
|
|
|
#20 |
|
12 years old
Join Date: Nov 2007
Posts: 94
Rep Power: 1
![]() |
Re: How to retrieve file name without path?
PathStripPath() is defined in the windows api and is your best bet for win32 and win64 development. i think it was already suggested tho
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 8th, 2007 11:50 PM |
| File path in Mac OS X | poopman | Python | 3 | Feb 2nd, 2007 8:59 PM |
| After execution - Error cannot locate /Skin File? | wchar | Visual Basic | 1 | Mar 5th, 2005 9:04 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |
| Structure char field to a disk file | ehab_aziz2001 | C++ | 0 | Feb 10th, 2005 2:42 PM |