dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] How to turn backslash to forward slash in windows environmental variable?

  1. #1
    Join Date
    Aug 2019
    Posts
    56

    [RESOLVED] How to turn backslash to forward slash in windows environmental variable?

    I necessarily need to change backslash to forward slash in windows environmental variable. Do you have any suggestions how can I get %programdata% path with forward slash after systemDrive?

    Code:
    TCHAR path[_MAX_PATH];
        _tcscpy(path, programdata);
        _tcscat(path, _T("\\myfile.txt"));
    Last edited by prako2; August 31st, 2019 at 04:39 AM.

  2. #2
    Join Date
    Aug 2019
    Posts
    56

    Re: How to turn backslash to forward slash in windows environmental variable?

    I found a way. Not very comfortable though.

    Solved:
    Code:
    TCHAR path[_MAX_PATH];
        _tcscpy(path, systemdrive);
        _tcscat(path, _T("/programdata"));
    Last edited by 2kaud; August 31st, 2019 at 08:02 AM.

  3. #3
    Join Date
    Aug 2019
    Posts
    56

    Re: How to turn backslash to forward slash in windows environmental variable?

    No, it's not a solution because programdata is not always the system drive subfolder

  4. #4
    Join Date
    Aug 2019
    Posts
    56

    Re: How to turn backslash to forward slash in windows environmental variable?

    Solved:
    Code:
    typedef std::basic_string<TCHAR> tstring;
     tstring pathbasic = tstring(programdata) + _T("\\myfile.txt");
     std::replace(pathbasic.begin(), pathbasic.end(), _T('\\'), _T('/'));
    Last edited by 2kaud; August 31st, 2019 at 08:03 AM.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,063

    Re: [RESOLVED] How to turn backslash to forward slash in windows environmental variab

    Why are you using environment variables when there are apis to retrieve this data?

  6. #6
    Join Date
    Aug 2019
    Posts
    56

    Re: [RESOLVED] How to turn backslash to forward slash in windows environmental variab

    Actually, this didn't help me. I spent a lot of time to understand that API I used does not recognize non-latin letters.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,063

    Re: [RESOLVED] How to turn backslash to forward slash in windows environmental variab

    Quote Originally Posted by prako2 View Post
    Actually, this didn't help me. I spent a lot of time to understand that API I used does not recognize non-latin letters.
    My point is there are api's (at least on Windows) that render using environment variables unnecessary and obsolete. The replacment api's (like other Windows apis) also support UNICODE.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)