0

i want to download a exe file with a url in c++, when the download path is with user Colin, its working, but when i do in the download path %username% then its not working. example: C:\Users\Colin\Desktop\hi\lol.mp3 = working C:\Users\%username%\Desktop\hi\lol.mp3 = dont working

MY CODE:

// the URL to download from
const wchar_t* srcURL = L"https://cdn.discordapp.com/attachments/815696193354203157/819662370224865320/lol.mp3";

// the destination file 
const wchar_t* destFile = L"C:\\Users\\Colin\\Desktop\\hi\\lol.mp3"; //Path where file should be saved.(Works only with Colin but i want %username%)

// URLDownloadToFile returns S_OK on success 
if (S_OK == URLDownloadToFile(NULL, srcURL, destFile, 0, NULL))
{

    system("start C:\\Users\\%username%\\Desktop\\hi\\lol.mp3");  //Path of the file where you want to open //works with both [%username and Colin%]

}
Temal
  • 51
  • 1
  • 6
  • Dev Studio has used `/` as a path separator for two decades now. Its time people stopped using `\\\`. – Martin York Mar 11 '21 at 21:09
  • 1
    @MartinYork whilst you can use forward slashes in most places on windows there are some places where only a backslash will work – Alan Birtles Mar 11 '21 at 21:11
  • 1
    @MartinYork It's not only Developer Studio, it's been there since the DOS days and is part of the OS itself. However, some paths can't be handled using forward slashes, though the ones in this code could. – Some programmer dude Mar 11 '21 at 21:11
  • 2
    "*Its time people stopped using ```\\```*" - another option is to stop using antiquated compilers that don't support *raw string literals*, which have existed for a decade now, eg: `const wchar_t* destFile = LR"(C:\Users\Colin\Desktop\hi\lol.mp3)";` – Remy Lebeau Mar 11 '21 at 21:31

0 Answers0