Solved

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

Posted on 2002-03-05
7
218 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
  • 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 139
Quicksort a dynamic deque 33 72
Getting IP address 8 78
Should CArray be used for a list of pointers in C++? 19 102
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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