473,238 Members | 1,885 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,238 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 30860
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.