midiboy Posted July 16, 2008 Posted July 16, 2008 (edited) Hi guys,I am having this problem now with my cmd script ....It is giving me a variable %CDROM% containing the driveletter in this format: X:\Now, CDSwitch requires a driveletter without the "\" at the end. Any idea how I can remove the backslash from the driveletter so I can use it in cdswitch?I hope someone has an idea ...Thanks all for your help with this !Alex Edited July 16, 2008 by midiboy
Yzöwl Posted July 16, 2008 Posted July 16, 2008 If you were to show us the script, (or at the very least the part of the script which creates the %CDROM% variable and its required usage), there may be a more appropriate method.However as a quick and easy example, try using %CDROM:~0,2%
midiboy Posted July 16, 2008 Author Posted July 16, 2008 (edited) Yzöwl,as always, you are the saviour of the day ! You already found the solution. Wonderful.Here´s the script by the way.I usually check for the existence of a file in the root of a drive using the usual method posted in this forum plenty of times. (SearchRoot2 in the example below).However, with some Dell Clients with mediacard readers, this method will provoke windows Exceptions, stopping the unattended installation. So I was looking for a way around this and found the tool fwdt.exeThis tool also searches for a specific file on removable drives. However, it may be doing that too quickly for some boards/ USB drives so one has to call it a few times. Now, in order to be sure that this won´t take forever, I am limiting this to 750 times. Should fwdt not work in some cases (I have no experience with this tool so I am not sure how reliable it really is), I will then switch to the usual method.The only problem with this approach is that fwdt.exe always attaches a backslash to the driveletter, while the usual method does not. Since cdswitch for instance requires a driveletter without the backslash, I needed to find a way to remove that from the variable.So, here´s the script:SET Count=1:SearchRoot1FOR /f "Tokens=1" %%i IN ('FWDT.exe -f aiwroot') DO SET CDROM=%%iIF NOT "%CDROM%"=="NULL" GOTO StartSetupSET /a Count+=1IF %Count%==750 goto SearchRoot2GOTO SearchRoot1:SearchRoot2For %%i in (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 if exist %%i:\aiwroot set CDROM=%%i::StartSetupECHO %CDROM%ECHO %CDROM:~0,2% Edited July 16, 2008 by midiboy
midiboy Posted July 22, 2008 Author Posted July 22, 2008 Hi Yzöwl,one followup question:The above is working fine. However, if I am doing this:set NEW=%CDROM:~0,2%Then the new variable "New" will not contain the content of CDROM minus the backslash but ~02 instead. Any ideas, why ? Any way around this ?As always, thanks for your help !Alex
Yzöwl Posted July 22, 2008 Posted July 22, 2008 My response to that question would depends on how and where you are setting the NEW variable!As a side note, This FWDT utility seems a little over the top for your intended use; which other methods of detecting the CD-ROM have you used?Since most of us are using XP or later, have you tried methods using WMIC or FSUTIL from a batch file?Method 1:- Mountvol and Fsutil with drivetype@Echo off&Setlocal enableextensionsFor /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do ( Fsutil fsinfo drivetype %%#|Find "CD-ROM">Nul&&(Set "CDROM=%%~d#"))If Not Defined CDROM Goto :Eof::Your code goes hereEcho:%%CDROM%%=%CDROM%Method 2:- Mountvol and Fsutil with filesystem check@Echo off&Setlocal enableextensionsFor /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do ( Fsutil fsinfo volumeinfo %%#|Find "CDFS">Nul&&(Set "CDROM=%%~d#"))If Not Defined CDROM Goto :Eof::Your code goes hereEcho:%%CDROM%%=%CDROM%Method 3:- WMI search for loaded CD@Echo off&Setlocal enableextensionsFor /f "usebackq skip=1" %%# In ( `2^>Nul Wmic Cdrom Where "MediaLoaded='true'" Get Drive`) Do ( Set "CDROM=%%~d#")If Not Defined CDROM Goto :Eof::Your code goes hereEcho:%%CDROM%%=%CDROM%Method 4:- WMI search for CD Drives@Echo off&Setlocal enableextensionsFor /f "usebackq skip=1" %%# In ( `2^>Nul Wmic Cdrom Where "MediaType='CD-ROM'" Get Drive`) Do ( Set "CDROM=%%~d#")If Not Defined CDROM Goto :Eof::Your code goes hereEcho:%%CDROM%%=%CDROM%Methods 2 and 3 only find a drive containing a disk whereas 1 and 4 will find empty ones too!Give one or two a go and see if they serve you better!
midiboy Posted July 22, 2008 Author Posted July 22, 2008 Hi Yzöwl,thanks for your detailed response. Here´s mine: 1. Well, I am using Vista mostly but everything I do should be backwards compatible so I am not sure which of your 4 methods works realiably in Vista and XP.2. I am not only installing from CDROM but I am also using a WDS Server in a few cases so any method that only works with CDROMS will not work too well.I guess that leaved only 1 and 4. I will give them a try, however, in the meantime I would like to keep using fwdt until I have tested the above throroughly.My response to that question would depends on how and where you are setting the NEW variable!Well, I am setting the "new" variable in the same script as the cdrom variable. I just had the idea to use a second variable, "new" instead of %CDROM:~0,2% all the time in the script for instance for the cdswitch utility.Any idea how I can get this to work easily ? If it won´t work, I will have to keep using %CDROM:~0,2% which is not the worst thing but doesn´t look as clean to me as the above solution.Bye,Alex
Yzöwl Posted July 22, 2008 Posted July 22, 2008 For now then, try changing your file to something like this:@Echo off& Setlocal enableextensionsSet Count=0:SearchRoot1For /f "delims=:" %%# In ('FWDT.exe -f aiwroot') Do Set CDROM=%%#:If Defined CDROM Goto StartSetupSet/a Count+=1If %Count% Leq 750 Goto SearchRoot1Goto :Eof:SearchRoot2For /f %%# In ('Mountvol^|Findstr [c-z]:\\') Do If Exist %%#aiwroot ( Set CDROM=%%~d#)If Not Defined CDROM Goto :Eof:StartSetupEcho:%CDROM%CDROM should never have the backslash regardless of the method employed!
midiboy Posted July 22, 2008 Author Posted July 22, 2008 (edited) Hi Yzöwl,Searchroot2 seems to work, however if SearchRoot1 is being used I get this as the result:ECHO %i:Any ideas ? maybe a typo somewhere ?Bye,AlexEdit: yeah, you had a "i" at the end of that line: For /f "delims=:" %%# In ('FWDT.exe -f aiwroot') Do Set CDROM=%%i:Changing that to a "#" does the trick.Thanks for your help !!Alex Edited July 22, 2008 by midiboy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now