henry3
asked on
Turn Path String.
Hi,
How to turn "c:\windows\system" path string into
"c:\\windows\\system" directly, in order to finish
some FILE operation.
Is there a MFC function?
How to turn "c:\windows\system" path string into
"c:\\windows\\system" directly, in order to finish
some FILE operation.
Is there a MFC function?
ASKER
HI,Mike
Thanks for your advice.
But I cannot find CString::Replace() at all.
When I use API SHFileOperation with the
parameter LPCSTR pFrom & LPCSTR pTo, the
format should be
"Driver1:\\XXX\\XXX\0Drive r2:\\XXX\0 " in order
to do some multiFiles operation.
So I wanna change the string format, is it
necessary? And how to do so?
Looking forward your suggestion.
Thanks for your advice.
But I cannot find CString::Replace() at all.
When I use API SHFileOperation with the
parameter LPCSTR pFrom & LPCSTR pTo, the
format should be
"Driver1:\\XXX\\XXX\0Drive
to do some multiFiles operation.
So I wanna change the string format, is it
necessary? And how to do so?
Looking forward your suggestion.
Ypu have han LPCSTR variable (assume lpszPath and strlen is nPathLen) with contains "Driver1:\XXX\XXX\0Driver2 :\XXX\0" where you want to replace the "\" with "\\".
If my uderstanding is right then this is what you can do.
CString szReplaceString(lpszPath);
szReplaceString.Replace("\ ","\\");
lpszPath = (LPCTSTR) szReplaceString.GetBuffer( nPathLen);
szReplaceString.ReleaseBuf fer();
Now the resulting lpszPath contains "Driver1:\\XXX\\XXX\\0Driv er2:\\XXX\ \0".
Hope this is what you needed.
If you are using VC just include the following code in you file to get the CString functions.
#include <afx.h>
Feel free to report any problems. My mail id is abdij_b@hotmail.com
If my uderstanding is right then this is what you can do.
CString szReplaceString(lpszPath);
szReplaceString.Replace("\
lpszPath = (LPCTSTR) szReplaceString.GetBuffer(
szReplaceString.ReleaseBuf
Now the resulting lpszPath contains "Driver1:\\XXX\\XXX\\0Driv
Hope this is what you needed.
If you are using VC just include the following code in you file to get the CString functions.
#include <afx.h>
Feel free to report any problems. My mail id is abdij_b@hotmail.com
> szReplaceString.Replace("\ ","\\");
That code won't compile.
If you don't have CString::Replace(), you're not using VC++ 6.0. Is that true? If so, you'll need to write your own version of the function--which isn't hard.
..B ekiM
That code won't compile.
If you don't have CString::Replace(), you're not using VC++ 6.0. Is that true? If so, you'll need to write your own version of the function--which isn't hard.
..B ekiM
Even if you fix abdij's code so it compiles, you'll find it doesn't work.
The Replace() function will fix the backwhacks in the first substring (up until the first '\0'), but won't touch anything afterwards.
The calls to GetBuffer() and ReleaseBuffer() don't do a darned thing except waste some memory and time.
I've never seen the syntax you mention for pTo in SHFILESTRUCT, so I don't know if you need double-whacks or not. You only need to escape the whacks if you're providing a string constant--that's for the C++ language, not the API.
..B ekiM
The Replace() function will fix the backwhacks in the first substring (up until the first '\0'), but won't touch anything afterwards.
The calls to GetBuffer() and ReleaseBuffer() don't do a darned thing except waste some memory and time.
I've never seen the syntax you mention for pTo in SHFILESTRUCT, so I don't know if you need double-whacks or not. You only need to escape the whacks if you're providing a string constant--that's for the C++ language, not the API.
..B ekiM
ASKER
Hi,men
Unfortunatly, I'm using VC++ 5.0 .
The syntax I mentioned for pTo in SHFILESTRUCT, appeared in tech artical
I've seen.
And I found if you didn't change "c:\xxx\xxx.txt" to "c:\\xxx\\xxx.txt",
some error result will come.
\0 is the separator of two directory.
If it isn't cerrect and necessary, how do I do?
Unfortunatly, I'm using VC++ 5.0 .
The syntax I mentioned for pTo in SHFILESTRUCT, appeared in tech artical
I've seen.
And I found if you didn't change "c:\xxx\xxx.txt" to "c:\\xxx\\xxx.txt",
some error result will come.
\0 is the separator of two directory.
If it isn't cerrect and necessary, how do I do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have another idea.
> I have another idea.
Huh?
..B ekiM
Huh?
..B ekiM
I'm not sure if you have the right reasons for doing this, but that's how you would do it.
..B ekiM