简体   繁体   中英

Running a cmd command within a C++ program using system() function

I want to move a file from its directory to C:\\Program files\\ so I ran this line of code

system("copy /y \"%~dp0\\myfile\" \"C:\\Program files\"");

When compiling and executing this line of code and running it as an admin, it returns an error saying "The system cannot find the path specified." Even though, it runs fine as a .bat script. What's the problem ?!

Try using environment variables like this:

system("copy /y \"%~dp0\\myfile\" \"%ProgramFiles%\"");

Or for access 32 bits Program Files folder use:

system("copy /y \"%~dp0\\myfile\" \"%ProgramFiles(x86)%\"");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM