CString Pathnames - backslash
-
Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)
-
Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)
im79 wrote:
Is there an easy way to substitute each "\" with "\\"?
CString::Replace()
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)
CString
has theReplace
method, but\
must be properly escaped, for instance:str.Replace("\\","\\\\")
Sure do you need this? :confused: :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)
don't !!!
'\\'
is only the representation in "design mode" (when coding) of the character\
. when you type a path in windows explorer, you type with a single**\**
, don't you ?
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
Hi everybody, i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex. "C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"? Thanks in advance :-)
im79 wrote:
Is there an easy way to substitute each "\" with "\\"?
why you need that?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
im79 wrote:
Is there an easy way to substitute each "\" with "\\"?
why you need that?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
Hi, i need the pathname to open the file. I get the filenames list form a CFileDialoge object. I found some examples in MSDN while reading about CFile where the pathnames have double back slashes. So i think i have to change the back slashes into double backslashes :confused:
-
Hi, i need the pathname to open the file. I get the filenames list form a CFileDialoge object. I found some examples in MSDN while reading about CFile where the pathnames have double back slashes. So i think i have to change the back slashes into double backslashes :confused:
i repeat : No ! paths are written with double backslashes only when in a string in your source code only, like
"
C:\\myfolder\\myfile.txt"
but this produces a paths to being like this internally :
C:**
\
myfolder\
**myfile.txtif you get a string from a CFileDialog for instance, you don't need to modify the path at all...!
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
im79 wrote:
Is there an easy way to substitute each "\" with "\\"?
why you need that?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
If you can help the man, do so. WHY he wants to do it is not important at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
If you can help the man, do so. WHY he wants to do it is not important at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001helping a guy doesn't always provide a working piece of code ! in this case, what the OP needed is useless, simply he didn't understand that double backslashes exists only because the backslash is the escapment character... i think what Alok did was to make the OP explicit his real need, and then Alok could explain him that he was wrong...
Don't know where to start ?
Refer the Forums Guidelines and ask a friend -
helping a guy doesn't always provide a working piece of code ! in this case, what the OP needed is useless, simply he didn't understand that double backslashes exists only because the backslash is the escapment character... i think what Alok did was to make the OP explicit his real need, and then Alok could explain him that he was wrong...
Don't know where to start ?
Refer the Forums Guidelines and ask a friendHelping someone doesn't necessarily include providing a piece of working code. Asking why someone wants to do something is irrelevant. If someone can't actually help, they should just STFU and let someone else step up. The post I responded too has already generated three needless replies and just makes noise that the OP has to wade through.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
If you can help the man, do so. WHY he wants to do it is not important at all.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
If you can help the man, do so. WHY he wants to do it is not important at all.
Sir, actually just want to know root cause of the problem.. numerous times people here at forums ask thing which they don't actually need! which create problem to them at later stage.. so to solve there problem.. some time people ask what actually they need.. Just like we do in URS/SRS phase.. You very well know that. secondly, if you see.. that guy require double slashes which you see he don't need! hope i clear my point.. if any thing wrong... i am sorry!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
i repeat : No ! paths are written with double backslashes only when in a string in your source code only, like
"
C:\\myfolder\\myfile.txt"
but this produces a paths to being like this internally :
C:**
\
myfolder\
**myfile.txtif you get a string from a CFileDialog for instance, you don't need to modify the path at all...!
Don't know where to start ?
Refer the Forums Guidelines and ask a friendHi toxcct, hi everybody, i' get the pathname CString with CFileDialog and then i pass it to function casts the CString to char* then it opens the file with fopenf. The C function fopenf is used because of a legacy code with a lot of fscanf calls with a specific foramt. I'm forecd to use theh old code for many reasons. Now, the orignal code workes with double backslashes, and if don't change the single backslashes to double, it won't work. Now i'm more confused :confused: Is there a difference when useing CFile::open() instead? In that case i need to rewrite the whole fscanf block :~ Thank u all for u help :)
-
Hi toxcct, hi everybody, i' get the pathname CString with CFileDialog and then i pass it to function casts the CString to char* then it opens the file with fopenf. The C function fopenf is used because of a legacy code with a lot of fscanf calls with a specific foramt. I'm forecd to use theh old code for many reasons. Now, the orignal code workes with double backslashes, and if don't change the single backslashes to double, it won't work. Now i'm more confused :confused: Is there a difference when useing CFile::open() instead? In that case i need to rewrite the whole fscanf block :~ Thank u all for u help :)
damn, don't you understand ??????? well, i sum up, but it's my last explanation ! 1. you choose your file with the CFileDialog 2. you then get the file path into a CString object 3. you pass this CString object directly to
fopen()
! there's no need to change a backslash into double backslashes, because you need this only when you hardcode strings in your source code (because the \ is the character escapment, and '\\' is the ascii code for the \ character) !!!
Don't know where to start ?
Refer the Forums Guidelines and ask a friend