Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2008, 8:02 PM   #11
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,890
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old May 1st, 2008, 10:21 AM   #12
CPU
Newbie
 
Join Date: Apr 2008
Posts: 15
Rep Power: 0 CPU is on a distinguished road
Re: How to retrieve file name without path?

thank you SANE for explaining what i try to imply
CPU is offline   Reply With Quote
Old Jul 18th, 2008, 4:55 PM   #13
CPU
Newbie
 
Join Date: Apr 2008
Posts: 15
Rep Power: 0 CPU is on a distinguished road
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
CPU is offline   Reply With Quote
Old Jul 18th, 2008, 5:23 PM   #14
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 551
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: How to retrieve file name without path?

Quote:
Originally Posted by CPU View Post
Sane you are right there is a standart
PathStripPath:
http://msdn.microsoft.com/en-us/libr...56(VS.85).aspx
That is only standard for MS-Windows operating system. Can't use it in *linx or any other os. So its not standard afterall. But, since you are writing a Windows program there is absolutely no harm in using that function -- just don't get confused between win32 api functions and standard C or C++ functions. The win32 api has hundreds of functions unique to that operating system -- not one of them are standard C/C++ functions.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Old Jul 18th, 2008, 6:05 PM   #15
CPU
Newbie
 
Join Date: Apr 2008
Posts: 15
Rep Power: 0 CPU is on a distinguished road
Wink Re: How to retrieve file name without path?

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
CPU is offline   Reply With Quote
Old Jul 24th, 2008, 12:08 PM   #16
francoispress
Newbie
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0 francoispress is on a distinguished road
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--;

}
francoispress is offline   Reply With Quote
Old Jul 24th, 2008, 5:38 PM   #17
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 551
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: How to retrieve file name without path?

Quote:
Originally Posted by francoispress View Post
The easiest way is to start from the back of the string and search for the "\\".
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.
Ancient Dragon is offline   Reply With Quote
Old Jul 25th, 2008, 7:16 AM   #18
francoispress
Newbie
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0 francoispress is on a distinguished road
Re: How to retrieve file name without path?

Quote:
Originally Posted by Ancient Dragon View Post
Sorry, but I disagree. The easiest way it to use strrchr() so that you don't have to reinvent the wheel.
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.
francoispress is offline   Reply With Quote
Old Sep 3rd, 2008, 6:34 AM   #19
devoox
Newbie
 
Join Date: Sep 2008
Posts: 3
Rep Power: 0 devoox is on a distinguished road
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.
devoox is offline   Reply With Quote
Old Sep 8th, 2008, 10:40 PM   #20
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 94
Rep Power: 1 null_ptr0 is on a distinguished road
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
null_ptr0 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC