473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

basename in C++

libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?
Thanks,
Peng

Oct 5 '06 #1
4 30897
Pe*******@gmail.com wrote:
libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?
Which thing is that?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 5 '06 #2
Victor Bazarov wrote:
Pe*******@gmail.com wrote:
>libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?

Which thing is that?
basename is part of the POSIX standard. On my system, the manual page for it
says:

DIRNAME(3) Linux Programmer’s Manual

NAME
dirname, basename - Parse pathname components

SYNOPSIS
#include <libgen.h>

char *dirname(char *path);
char *basename(char *path);

DESCRIPTION
Warning: there are two different functions basename() - see below.
The functions dirname() and basename() break a null-terminated
pathname string into directory and filename components. In the
usual case, dirname() returns the string up to, but not including,
the final ’/’, and basename() returns the component following the
final ’/’. Trailing ’/’ characters are not counted as part of the
pathname.
So the answer is: There is no standard C++ function to do that. In standard
C++, there is no such thing as directories, so there no support whatsoever
for it.

Oct 5 '06 #3
"Pe*******@gmail.com" <Pe*******@gmail.comwrites:
libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?
foo = basename(bar) works pretty much like:

#v+
foo = strrchr(bar, '/');
foo = foo ? foo + 1 : bar;
#v-

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Oct 5 '06 #4
"Pe*******@gmail.com" <Pe*******@gmail.comwrites:
libgen.h has the basename command. But it is not a C++ head file.
Is there any C++ head file have a function or a class doing the same
thing?
If you're just looking for basename, you should probably use the posix
thing.

There is, however, a boost library for this stuff (filesystem). Note
that they call basename leaf, and their basename has something to do
with file extensions.

Regards,

Jens
Oct 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
1
by: Sean Berry | last post by:
I have an online ftp type website for a customer that I wrote in a cgi perl script. If the person is trying to upload a file that already exists on the server I am printing a message telling...
1
by: Wild Pete | last post by:
Is there an equivalent to a "basename" in javascript that returns the last part of a file name? For example, given "C:\My Documents\test.txt" and "/usr/local/test.txt", both should return...
0
by: rithish | last post by:
Hello. We are on PHP 5.0.2 LINUX system. Since an hour ago, the function basename() started resulting inconsistent values. print ( "dirname - " . dirname ( __FILE__ ) . "<br>\n" ); print (...
1
by: Peter Saffrey | last post by:
I'd like to resurrect this subject: http://groups.google.com/group/comp.lang.python/browse_frm/thread/11146344b03e72b6/6b2a3b0c0e902114?lnk=gst&q=basename&rnum=2#6b2a3b0c0e902114 If I have a...
2
by: Thomas Ploch | last post by:
Hello, I have a cgi script that handles fileuploads from windows and *nix machines. i need os.path.basename(filename) to get the pure filename. For *nix, thats not a problem, but for windows,...
0
by: Salve =?iso-8859-1?Q?H=E5kedal?= | last post by:
$var = "/home/user/dir/file" // To extract dir from $var, is echo basename(dirname($var)); // a silly thing to do? Salve
5
by: David d'Angers | last post by:
hi group the following lines are taken from basename.c of the linux coreutil group of programs i don't understand the meaning of several of the functions: initialize_main (&argc, &argv); why...
6
TheServant
by: TheServant | last post by:
Hey guys, I am trying to figure out a more efficienct structure for my website and how it handles files and contents. I am trying very hard to separate all my html and php and although it is going...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.