• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

locating the CD Rom

When using batch file I want to copy a file from the cd rom to another directory... the problem is that the cd rom drive could be d:,e:,f: or something else.

I know that you can use the registry like %SystemRoot%/system is there a way to do this in a batch file to find the registered CD rom drive...

need a quick answer.... cheers
1 Solution
Batch files are DOS.  DOS doesn't "know" about windows or the registry.

What you can do is have a environmental variable defined that specifies the CD drive letter and then use that variable in your batch file.  You can set the environmental variable in the autoexec.bat file so that it will allways be set.  Of course, it has to be set manually there, then other batch files can use that setting.
Another option is to write a win32 console program that takes a drive letter as a parameter and uses GetDriveType() to see if the drive is a CD rom.  Then it returns 0 if it is and non-zero if it is not.  The batch file can use this program with the IFERRORLEVEL statement to determine if a drive letter is for a CD ROM.
borris111698Author Commented:
the batch file will use %SystemRoot%\system as in the %systemroot% is usually c:\windows... the batch file will run from a cd so there is no chance of changing the autoexec.bat file
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

If this is a batch file that is run repeatidly, you can change the autoexec once--manually to set the environent varaible.  Then your batch file can use it.

Or you can use my other suggestion, which is to write a win32 console program to help you.

DOS does not provide the information you want.
YOu can also ask the user for this information, using PROMPT and ASK.

You said that the batch file is running on the CD itself, right?

Then you can create a text file in the TEMP directory with the drive and directory that the batch file is running in using the CD command.

When you type "CD" with no parameters the current drive and directory are displayed.  This can be redirected to a file:

cd > %temp%\cd-drive
rem ** create new batch file
copy part1.dat + %temp%\cd-drive + part2.dat %temp%\runme.bat
call %temp%\runme.bat

or something along these lines.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now