Here is the copy statement I have currently.
I am looking to replace the F: with %cdrom% so that this script will work no matter what computer it is used on.
XCOPY F:\*.* .\disk2\ /C /S /D /Y /I
Here is the copy statement I have currently.
I am looking to replace the F: with %cdrom% so that this script will work no matter what computer it is used on.
XCOPY F:\*.* .\disk2\ /C /S /D /Y /I
Unfortunately, it's not easy to detect CD-ROM drive in batch files. You'd have to use some tools for this. Even if you have some tool that can successfully detect CD-ROM/harddisk/USB status, there still can be multiple CD-ROM drives or virtual drives.
One of the easiest ways to do this (although you can't rely on it): Trying to copy and delete a temporary file to D,E,F,G... until you get an error (this gives you the first read-only drive which often is the CD-ROM drive).
You should also think about asking the user for the drive letter or at least give him the possibility to define %CDROM%.
There are other ways to detect CD-ROM drives floating around in the net (f.e. here), but they are often only working with an particular OS and rely on tools like registry editors, so you should think about using some non-batch solution or an additional tool instead.
I just pieced together the following little script:
@echo off
setlocal enableextensions enabledelayedexpansion
set count=0
for /f "skip=1 tokens=1* delims= " %%x in ('wmic cdrom get drive^,name') do (
if not [%%y]==[] (
set /a count+=1
set drive_!count!=%%x
set drivename_!count!=%%y
)
)
if %count%==0 goto error
if %count%==1 set cdrom=%drive_1%
if %count% GTR 1 call :more
if defined ERROR goto :eof
XCOPY %cdrom%\*.* .\disk2\ /C /S /D /Y /I
goto :eof
:more
set ERROR=
set letters=
echo %count% CD ROM drives found
for /l %%x in (1,1,%count%) do (
echo. !drive_%%x! - !drivename_%%x!
set letters=!letters!!drive_%%x:~0,1!
)
choice /C %letters% /M "Enter the drive letter to copy from" /N
if errorlevel 255 set ERROR=1
if not errorlevel 1 set ERROR=1
set cdrom=!drive_%errorlevel%!
goto :eof
:error
1>&2 echo No CD ROM drive found
goto :eof
Should be fairly straightforward. I'm getting a list of CD ROM drives with wmic
and store their drive letters and captions. If there is only one CD ROM drive the selection is unambiguous, so copying can start right away, otherwise the user is prompted.