Computer Hope
Microsoft => Microsoft DOS => Topic started by: 1963Ford on January 26, 2009, 03:37:40 PM
-
Here's the code that I am working with:
rem @echo off
setlocal enable delayedexpansion
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "Removeable"') do (
echo %%i:
if %%i LSS E (
echo Sorry, no USB Flash Drive available.
pause
EXIT
)
)
echo %%i:
echo All is well.
:FINALEND
I'm going a little nuts over this, as I think it should be fairly simple, but DOS is so picky. LOL Thanks in advance. If it isn't possible to remove the colon, then it's time to finagle another angle to make it work.
-
Use
Prompt $P$H$H
You will then see only the drive Letter as for the first $H will remove the \ and the second $H will remove the : ( colon )..... The $H is a backspace to delete the characters at the tail end of the default $P prompt of C:\ giving you C
Does this help when you see just the drive letter?
To set it back to C:\> simply add PROMPT $P$G at the end of the batch to set back to C:\>
-
Dave, I think you misunderstand the question.
-
Diskpart doesn't come back with a colon with the drive letter. Though for what you're doing this might be more efficient:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| find /i "Removeable"') do (
echo USB disks are:
if defined %%i echo %%i
goto here)
echo no USBs
:here
pause
exit
FB
-
FB - That's exactly what I was looking for. I was going the long way and you did it the short and simple way. Thanks. ;D
Thanks to all who posted! :)