Turn Path String.

  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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use CString::Replace("\\", "\\\\");

I'm not sure if you have the right reasons for doing this, but that's how you would do it.

..B ekiM
henry3Author Commented:
   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\0Driver2:\\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.
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);
lpszPath = (LPCTSTR) szReplaceString.GetBuffer(nPathLen);

Now the resulting lpszPath contains "Driver1:\\XXX\\XXX\\0Driver2:\\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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

> 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
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

henry3Author Commented:
   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?
If you code a string literal, then you need to have both backslashes.  Like this:

   char* pstr = "c:\\xxx\\xxx.txt";

If you're getting the string from another source (like the user typing it in), you don't need to double the backslashes.

..B ekiM

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
henry3Author Commented:
I have another idea.
> I have another idea.


..B ekiM
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.