I have a url path(CString) how do i get the file name from it in
CString ?? I dont want to use _tsplitpath ..
>Hi All,
>
>I have a url path(CString) how do i get the file name from it in
>CString ?? I dont want to use _tsplitpath ..
>
personally I always convert strings to c++ strings ...
string dir = pathName;
dir.erase(dir.find_last_of("\\", dir.length()-1) + 1, dir.length());
But that entails the extra step of converting CString to a c++ string
... if I recall correctly, this doesn't work
CString pathname = "foo\file";
string dir = pathname;
But this does
CString pathname = "foo\file";
string dir;
dir = pathname;
--
Joe Cosby
http://joecosby.com/
People ask me if I've ever been called a Nazi. I answer that no one has
ever had dreams of being tied down and sexually ravished by someone dressed
as a liberal.
- P.J. O'Rourke
:: Currently listening to Someone Else's Dream, 1996, by Laurie Anderson, from "The Ugly One with the Jewels and other stories"
On Dec 31, 12:46 pm, Zapanaz <http://joecosby.com/code/mail.pl> wrote:
> On Sun, 30 Dec 2007 23:02:09 -0800 (PST), jklioe <ranu2...@gmail.com>
> wrote:
>
> >Hi All,
>
> >I have a url path(CString) how do i get the file name from it in
> >CString ?? I dont want to use _tsplitpath ..
>
> personally I always convert strings to c++ strings ...
>
> string dir = pathName;
> dir.erase(dir.find_last_of("\\", dir.length()-1) + 1, dir.length());
>
> But that entails the extra step of converting CString to a c++ string
> ... if I recall correctly, this doesn't work
>
> CString pathname = "foo\file";
> string dir = pathname;
>
> But this does
>
> CString pathname = "foo\file";
> string dir;
> dir = pathname;
>
> --
> Joe Cosbyhttp://joecosby.com/
Actually, it is not that easy.
You need to:
1. Decode the URL (it can be escaped like containing %20 and so on)
2. Convert from UTF8 to UTF16 (URIs can contain UTF-8 characters)
3. Strip all unneccessary path components. Web URL愀 can contain parameters like
?session=blahblah at the end
You could then use something like
int pos = url.ReverseFind(_T('/'));
CString filepart;
if (pos != -1)
filepart = url.Mid(pos+1);
Norbert
CFileFind finder;
if(!finder.FindFile(FilePath))
return FALSE;
finder.FindNextFile();
CString FileName=finder.GetFileName();
FileName.Truncate(FileName.GetLength()-4);
I still did not understand y FindNextFile is necessary before calling
GetFileName(In fact before calling many of the attribute member
functions of CFileFind ) ?? Can any one clear my doubt
On Dec 31, 3:15 pm, Norbert Unterberg <nunterb...@newsgroups.nospam>
wrote:
> jklioe schrieb:
>
> > Hi All,
>
> > I have a url path(CString) how do i get the file name from it in
> > CString ?? I dont want to use _tsplitpath ..
>
> Actually, it is not that easy.
>
> You need to:
> 1. Decode the URL (it can be escaped like containing %20 and so on)
> 2. Convert from UTF8 to UTF16 (URIs can contain UTF-8 characters)
> 3. Strip all unneccessary path components. Web URL´s can contain parameters like
HTH,
Serge.
http://www.apptranslator.com - Localization tool for your MFC applications
"jklioe" <ranu...@gmail.com> wrote in message
news:adad6626-f318-4f11...@u10g2000prn.googlegroups.com...
On Dec 31, 4:08 pm, "Serge Wautier" <se...@wautier.nospam.net> wrote:
> AfxParseURL()
>
> HTH,
>
> Serge.http://www.apptranslator.com- Localization tool for your MFC applications
>
> "jklioe" <ranu2...@gmail.com> wrote in message
>
> news:adad6626-f318-4f11...@u10g2000prn.googlegroups.com...
>
>
>
> > Hi All,
>
> > I have a url path(CString) how do i get the file name from it in
> > CString ?? I dont want to use _tsplitpath ..- Hide quoted text -
>
> - Show quoted text -
jklioe:
C:\temp\xx.txt is a path, not an url.
--
David Wilkinson
Visual C++ MVP
For example, in writing a recipe about shallots I wanted to include something about
Tennyson's poem "The Lady of Shallot". Note also that a filename may not be present,
because the default is index.htm (and a number of other possibilities based on some rules
about how to search for the default Web page)
http://www.google.com/search?hl=en&q=lady+shallot
So the code below, for
woud deliver an empty string, but for
would deliver a "file name" of www.flounder.com, which is not actually a file name at all.
joe
On Mon, 31 Dec 2007 11:15:51 +0100, Norbert Unterberg <nunte...@newsgroups.nospam>
wrote:
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
TCHAR file[MAX_PATH];
TCHAR ext[MAX_PATH];
_tsplitpath(input_string, NULL, NULL, file, ext);
TCHAR filename[MAX_PATH];
_tmakepath(filename, NULL, NULL, file, ext);
done! There is no reason to NOT use _tsplitpath in this context.
Note that in VS2005 and beyond, you should really use _tsplitpath_s and _tmakepath_s to
make sure there are never any buffer overruns.
joe
On Mon, 31 Dec 2007 06:43:46 -0500, David Wilkinson <no-r...@effisols.com> wrote:
>jklioe wrote:
>> Thanks but the url is something like C:\\temp\xx.txt and i need only
>> "xx"
>
>jklioe:
>
>C:\temp\xx.txt is a path, not an url.
I ll change my code ...
On Dec 31 2007, 11:31 pm, Joseph M. Newcomer <newco...@flounder.com>
wrote:
> Which then goes back to the question of why not use _tsplitpath? That would be the
> correct way to handle a file name!
>
> TCHAR file[MAX_PATH];
> TCHAR ext[MAX_PATH];
> _tsplitpath(input_string, NULL, NULL, file, ext);
>
> TCHAR filename[MAX_PATH];
> _tmakepath(filename, NULL, NULL, file, ext);
>
> done! There is no reason to NOT use _tsplitpath in this context.
>
> Note that in VS2005 and beyond, you should really use _tsplitpath_s and _tmakepath_s to
> make sure there are never any buffer overruns.
> joe
>
> On Mon, 31 Dec 2007 06:43:46 -0500, David Wilkinson <no-re...@effisols.com> wrote:
> >jklioe wrote:
> >> Thanks but the url is something like C:\\temp\xx.txt and i need only
> >> "xx"
>
> >jklioe:
>
> >C:\temp\xx.txt is a path, not an url.
>
> Joseph M. Newcomer [MVP]
> email: newco...@flounder.com
PathFindFileName()
-- David
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
PathFindFileName() expects a MAX_PATH output buffer, so I imagine it takes
care to truncate the output to fit MAX_PATH.
Thanks,
David