Solved

Need to Find Path to CD Rom for System() Command

Posted on 2002-03-05
7
221 Views
Last Modified: 2010-04-01
I am writing an application to be burned on a CD that needs to access other files on the same CD.  For instance, one application on this CD needs to open a .html file also located on the same CD.  For testing purposes, I am using ...

system("index.html");

but this only works with the c: drive.  Obviously, I can also type c:/temp/index.html or whatever the path may be.  However, this application is going to be used on many different computers.  Many computers have the CD as drive d: but also many have it as a drive e: or drive f:. Somehow, I need to find the path to the current user's CD drive and then use that path within the system() command.  NOTE: The system() command uses a const char * as a parameter and I have not been able to figure out how to use a variable instead of a string as shown above.  When I try to use a variable ...
     const char *temp1 = "c:/temp/acrord32.exe";
     system("temp1");
a message tells me that temp1 is not recognized as a internal or external command or operable program.
However, system("c:/temp/acrord32.exe");  works fine.  
Question is:  How do I find the path of the CD ROM and then get that path to work in the system command?  I am assuming that I will need a variable for the path so I can add the path to my application.
0
Comment
Question by:guile1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 6843151
You usually would use "GetDriveType()":

char Get1stCDDriveLetter() {

 char c = 'a';
 char acRoot [ MAX_PATH];

 while ( 1){
   sprintf ( acRoot, "%c:\\", c),

   if ( DRIVE_CDROM == GetDriveType ( acRoot)) {
        return ( c);
   }

   c++;
  }

 return 0;
}

This will return the CDROm drive letter...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6843152
Oh, and you would use it like

const char *temp1 = "%c:/temp/acrord32.exe";

char acPath [ MAX_PATH];

sprintf ( acPath, temp1, Get1stCDDriveLetter());

system ( acPath);
0
 
LVL 86

Expert Comment

by:jkr
ID: 6843165
Wait a minute - is your app already started from the CD? If so, it would be easier to use "GetModuleFileName ( NULL)" and use that information...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 6843173
Ooops, BTW, make

char c = 'a';

read

char c = 'd';

I think we can safely assume that :o)
0
 

Author Comment

by:guile1
ID: 6843180
Very good!  Thanks.
0
 
LVL 1

Expert Comment

by:jdrescher
ID: 6843823
>Wait a minute - is your app already started from the CD? If so, it would be easier to use "GetModuleFileName
( NULL)" and use that information...

Yes. You better use this instead, because the user may have more than one cdrom drive. My server has three..
0
 
LVL 86

Expert Comment

by:jkr
ID: 6845029
>>because the user may have more than one cdrom drive

That's why the function is named 'Get1stCDDriveLetter()' :o)
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question