GetCurrentDirectory + '\'

This is a discussion on GetCurrentDirectory + '\' within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, If I use GetCurrentDirectory to get the current path for creating a file, it returns an un-escaped path ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    GetCurrentDirectory + '\\'

    Hi all,

    If I use GetCurrentDirectory to get the current path for creating a file, it returns an un-escaped path causing an error.

    How can I easily get the current directory with escaped '\' i.e.

    c:\\my\\path

    rather than

    c:\my\path

    Or am I just being stupid.

    TIA, rotis23

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    OK, I was being stupid.

    I was running as a service and it was returning :

    C:\WINDOWS\system32

    How can I get the path of the service executable?

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278

    Re: GetCurrentDirectory + '\\'

    Originally posted by rotis23
    Hi all,

    If I use GetCurrentDirectory to get the current path for creating a file, it returns an un-escaped path causing an error.

    How can I easily get the current directory with escaped '\' i.e.

    c:\\my\\path

    rather than

    c:\my\path

    Or am I just being stupid.

    TIA, rotis23
    To explain where your thinking went wrong - the slashes that exist in the path have already 'been escaped'. Just because the C/C++ language (and apparently the code for this forum) uses '\\' as an escape character prefix for other unprintable characters, it means that it now has to use something else for a real '\\' - they chose '\\\'. So, when you type '\\\', you are not making a string with '\\\' (i.e. 2 characters), you are making a string with '\\' (i.e. 1 character). I hope that helps your understanding a bit.

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Look into GetModuleFileName().
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Thats the answer - thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetCurrentDirectory()
    By neandrake in forum Windows Programming
    Replies: 2
    Last Post: 12-06-2003, 11:24 AM
  2. GetCurrentDirectory problems.
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-01-2003, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21