-3

It doesn`t work because it could be "Start menu", not Start menu . But system("_path_"Start Menu"_path_") gives an error (system('_path_"Start Menu"_path_') also gives an error). How to fix it?

Code:

system("move C:\\Users\\%USERNAME%\\Downloads\\a.exe C:\\Users\\%USERNAME%\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup");

drescherjm
  • 10,365
  • 5
  • 44
  • 64
fur1ous
  • 59
  • 6
  • 2
    You need to quote the path with spaces in it, then it works. – Konrad Rudolph Apr 10 '21 at 15:27
  • The syntax of the command is incorrect. it gives – fur1ous Apr 10 '21 at 15:28
  • 1
    You need double-quotes around the paths. And you need to *escape* the double-quotes since they are in a string. – Some programmer dude Apr 10 '21 at 15:31
  • I know, in python you could `system('_path_"Start Menu"_path')` but in c++ it gives error because it should be `system(" ")`, not `system(' ')` – fur1ous Apr 10 '21 at 15:32
  • @Someprogrammerdude can you write please the whole code? – fur1ous Apr 10 '21 at 15:33
  • 2
    @fur1ous You need to escape the double quotes, just as you escaped the backslashes in the path (you could do the same in Python, incidentally): `\"`. – Konrad Rudolph Apr 10 '21 at 15:34
  • 2
    As any decent [book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), tutorial or class should have mentioned, you need to *escape* double quotes inside a string. As in `std::cout << "This strings contains \"double quotes\"\n";` – Some programmer dude Apr 10 '21 at 15:38
  • I am sorry, i am noob at this: so it could be `Windows\"Start Menu\"\nPrograms` ? @Someprogrammerdude – fur1ous Apr 10 '21 at 15:43
  • If you would write the command in a Windows command window, how would you place the quotes for the command to be correct? Do the same here in your program, but remember the *escapes* (backslashes). – Some programmer dude Apr 10 '21 at 15:45
  • You may want this: [https://en.cppreference.com/w/cpp/filesystem/rename](https://en.cppreference.com/w/cpp/filesystem/rename) – drescherjm Apr 10 '21 at 15:50

1 Answers1

0
system("move \"<src_path>" \"<dest_path>\"");

Also, if you need escape a " characters inside of a path, use \ to escape, but as far as I know, Windows would not allow you to name entities with particular set of special characters.