1.

Solve : detect cd rom from the batch file?

Answer»

I want to detect the cd ROM drive letter from the batch file and POINT it into my file which is on a cd.I want to access the file on a cd in different systems with different cd drive letters and access my file by means of a batch file.please help me in this regardThis code search your file in all the drive letters for devices (DISK, CD-ROM USB pendrive, diskette, ...). You can remove the letter A, B (maybe C) if you are sure that the CD isn't in this drives.

Code: [Select]@echo off
set DRIVE=
for %%D in (a b c d e f g h i j k l m n o p q r s t u v w X y z) do vol %%D: >NUL 2>NUL && if exist %%D:\PathTo\MyFile.txt set DRIVE=%%D

if not defined DRIVE echo I can't find the file && goto END

type %DRIVE%:\PathTo\MyFile.txt

:END
You must change the "PathTo\MyFile.txt" for yours.
You could have a problem if exist ANOTHER path/file in other drive with the same name "PathTo\MyFile.txt", it will work with the last unit found.

P.S. You dont posted your OS, this code works for W2000 and laters.



Discussion

No Comment Found