Computer Hope

Microsoft => Microsoft DOS => Topic started by: 1963Ford on January 26, 2009, 03:37:40 PM

Title: Is it possible to remove the colon from the drive letter
Post 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.
Title: Re: Is it possible to remove the colon from the drive letter
Post by: DaveLembke on January 26, 2009, 04:01:31 PM
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:\>
Title: Re: Is it possible to remove the colon from the drive letter
Post by: Dias de verano on January 27, 2009, 05:08:18 AM
Dave, I think you misunderstand the question.
Title: Re: Is it possible to remove the colon from the drive letter
Post by: fireballs on January 27, 2009, 05:29:37 AM
Diskpart doesn't come back with a colon with the drive letter.  Though for what you're doing this might be more efficient:

Code: [Select]
@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
Title: Re: Is it possible to remove the colon from the drive letter
Post by: 1963Ford on January 27, 2009, 06:35:40 AM
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!  :)