Public Group

# Cant find Program Files?

This topic is 3606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am using system("start c:\\PyroSlide.pps"); to open an external power point presentation from within my program. And it works when the file is in the c root. When I move it to Program Files though, system("start c:\\Program Files\\PyroSlide.pps"); A dialog says "Windows cannot find c:\Program" and if I remove the space, it says "Windows cannot find c:\ProgramFiles" What am I doing wrong? Thanks, Matt I am using c++ on windows xp.

##### Share on other sites
system("start c:\\\"Program Files\"\\PyroSlide.pps"); // start C:\"Program Files"\PyroSlide.pps

or

system("start \"c:\\Program Files\"\\PyroSlide.pps\""); // start "C:\Program Files\PyroSlide.pps"

Directory names with spaces are a !@#\$%. [smile]
The system is interpreting your command as program "start" with parameters "C:\Program" and "Files\PyroSlide.pps", using quotes helps the system interpret spaces as part of the string instead of as a argument separator. Make sense?

##### Share on other sites
When you use system, you're sending a command as if you're using the DOS-like command line. This means spaces separate one argument from another, whether they were intended to be part of a file name or not. You can fix this by putting the whole filename in quotes (remember to escape them properly in a C++ string):
system("start \"C:\\Program Files\\PyroSlide.pps\"");

EDIT: hehe, beat me to it...

##### Share on other sites
In any case, it'd be better to just use ShellExecute() instead of system() to do this. Just pass the name of the file as the third argument and you don't need to worry about escaping spaces.

##### Share on other sites
Ooh, ok gotcha, thanks a lot guys :)

Matt

##### Share on other sites
Quote:
 Original post by SiCraneIn any case, it'd be better to just use ShellExecute() instead of system() to do this. Just pass the name of the file as the third argument and you don't need to worry about escaping spaces.
Or running the correct program, or working on machines where program files isn't that directory (Such as XP-64, where it's "Program Files (x86)").

EDIT: Ah, you're using start, not executing the powerpoint EXE.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013165
×