Escape Character in directory path

  • Follow


Hi

I need to pass a path to FindFirstFile() that is specified by the user,
problem is that all \ characters need to be prefixed with another \, what is
the easiest way to do this short of scanning the entire string and replacing
a \ with \\.

Kind Regards

Rich Strang


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply riky_rang (8) 1/4/2004 11:43:42 PM

Rich Strang wrote:
> Hi
> 
> I need to pass a path to FindFirstFile()

This is a Windows function, not a standard C++ function.  Discussion of
platform-specific libraries should generally be done on other groups.

> that is specified by the user, problem is that all \ characters need to be
> prefixed with another \,

No they don't.  That is something you need to do in source code, not in
memory.

> what is the easiest way to do this short of scanning the entire string and
> replacing a \ with \\.

Tell the user to do it. ;-)

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Ben 1/5/2004 9:50:04 PM


Rich Strang wrote:
> Hi
> 
> I need to pass a path to FindFirstFile() that is specified by the user,
> problem is that all \ characters need to be prefixed with another \, what is
> the easiest way to do this short of scanning the entire string and replacing
> a \ with \\.

Actually, you don't need to do a thing.  The string containing
\ characters is just fine.

The problem you may be thinking about is with *literal* strings
in your program.  It's not the fact that the string contains \
characters:  the problem is precisely that the string DOES NOT
contain the \ characters that it should:

"c:\temp\total.txt"

Does not contain a single \ character -- it does contain two
TAB characters, though.  But if the user enters the above
string, then your string variable will indeed contain the
two \ characters and everything will work fine.

BTW, it is normally recommended to use / for paths -- either
on Unix/Linux or on DOS/Windows, it works.  This, of course,
applies to *literal strings* in your program containing
paths.  For instance:

"c:/temp/total.txt"

will work fine.

HTH,

Carlos
--

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Carlos 1/5/2004 9:59:55 PM

2 Replies
560 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/23/2012 1:12:06 AM


Reply: