?
Solved

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

Posted on 2002-03-05
7
Medium Priority
?
223 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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

777 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