Is there a Windows or C++ library function to break down a Filepath?

R

Ramon F Herrera

My application receives a filepath as an argument. Obviously, it can
come in several formats, such as:

filename.ext

..\filename.ext

...\..\filename.ext

this\is_a\relative\path\finally.ext

C:\fully\qualified\path\filename.ext

....and so on.

In Unix there is a function which will do the right thing in every
case, splitting the path into a base and a filename.

Is there such thing, something equivalent in Windows programming?

TIA,

-Ramon
 
A

Alf P. Steinbach

* Ramon F Herrera:
My application receives a filepath as an argument. Obviously, it can
come in several formats, such as:

filename.ext

.\filename.ext

..\..\filename.ext

this\is_a\relative\path\finally.ext

C:\fully\qualified\path\filename.ext

...and so on.

In Unix there is a function which will do the right thing in every
case, splitting the path into a base and a filename.

Is there such thing, something equivalent in Windows programming?

Windows programming is off-topic in clc++.

Check out the Boost library's general file handling.

Cheers, & hth., & please stop asking for off-topic answers!,

- Alf
 
R

Ramon F Herrera

* Ramon F Herrera:






Windows programming is off-topic in clc++.

Check out the Boost library's general file handling.

Cheers, & hth., & please stop asking for off-topic answers!,

- Alf

Ah, I had forgotten that this is the NG with the self-appointed Nazis!

Were you ever in the soup business in Manhattan?

You may go ahead and erase the Windows part, the rest of the question
remains.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? <--Maybe for you


(1) For those of us who think in terms of stacks, top posting is more
natural.

(2) The material may be lost in the lower lines. Perhaps what you
write has no much relevane, but what I write does.

(3) If you drive on a road, they place text lines in the reverse
order. They don't want you to drive backwards.

(4) The StarWars intros also uses such scheme

(5) Now go ahead and tell me that a discussion of your .signature is
off topic!

-Ramon
 
R

Ramon F Herrera

* Ramon F Herrera:






Windows programming is off-topic in clc++.


Check out the Boost library's general file handling.


Ooops, I went trigger happy, shot from the hip and didn't even realize
you actually gave some useful info, Alf.

Thanks!

For the record: I am not too fond of the Windows crowd, their ways and
means, and have tried my best to stay on the side of standards,
interoperability (i.e., non-Microsoft), IETF, OSS, etc.

-Ramon
 
L

Leclerc

Ah, I had forgotten that this is the NG with the self-appointed Nazis!

Why do you feel so offended? You *did* ask off topic question. It also
implies that you don know (don't want to?) how to use MSDN.

You may go ahead and erase the Windows part, the rest of the question
remains.
and you got answer: www.boost.org


(5) Now go ahead and tell me that a discussion of your .signature is
off topic!

it is.


cheers,
Gordan
 
G

Guest

Ah, I had forgotten that this is the NG with the self-appointed Nazis!

Were you ever in the soup business in Manhattan?

You may go ahead and erase the Windows part, the rest of the question
remains.

The rest of the question remains off-topic. C++ does not have any notion
of file-path, all it knows is that if you pass a certain string to the
system it will interpret that as the name of a file. While not very
common there are alternative schemes which does not store files in
directories.

Anyway, by using rfind() to look for the first / (or \) character you
should quite easily be able to separate out the filename from the path.
 
A

Andrew

My application receives a filepath as an argument. Obviously, it can
come in several formats, such as:

filename.ext

.\filename.ext

..\..\filename.ext

this\is_a\relative\path\finally.ext

C:\fully\qualified\path\filename.ext

...and so on.

In Unix there is a function which will do the right thing in every
case, splitting the path into a base and a filename.

Is there such thing, something equivalent in Windows programming?

TIA,

-Ramon


Look to the Shell Path functions in MSDN.
One of them is PathFindFileName which takes a path and returns the
filename
 
J

jtorjo2007

My application receives a filepath as an argument. Obviously, it can
come in several formats

Why don't you use boost::filesystem library? It's cross-platform.


Best
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top