PC Review


Reply
Thread Tools Rate Thread

Checking whether parameter is a drive letter

 
 
Rich Pasco
Guest
Posts: n/a
 
      9th Jul 2008
Suggestions are invited on the simplest and most reliable way
(in a BAT file command script) to check whether a command-line
parameter (e.g. %1 or %2) designates a valid drive letter (with
its colon, e.g. C: or D: )?

- Rich
 
Reply With Quote
 
 
 
 
Rich Pasco
Guest
Posts: n/a
 
      9th Jul 2008
Rich Pasco wrote:

> Suggestions are invited on the simplest and most reliable way
> (in a BAT file command script) to check whether a command-line
> parameter (e.g. %1 or %2) designates a valid drive letter (with
> its colon, e.g. C: or D: )?


This should work with Windows 2000 and newer.

Below is what I have now. I can't seem to fool it into making an
mistake, but the checking feels awkward. Does anyone have a more
elegant solution?

============================
set drive=%~d1
if /I not %~1==%drive% (
echo Parameter "%~1" does not name a drive.
goto end
)
if not exist "%drive%" (
echo Drive %drive% is not available.
goto end
)
echo drive is %drive%
.... useful part of script goes here...
:end
============================

- Rich
 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      9th Jul 2008
"Rich Pasco" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Suggestions are invited on the simplest and most reliable way
> (in a BAT file command script) to check whether a command-line
> parameter (e.g. %1 or %2) designates a valid drive letter (with
> its colon, e.g. C: or D: )?
>
> - Rich


Rich,

Take a look at the post entitled 'Batch file to show Network drives', I
believe you'll find relevant info. in there.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l



 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      9th Jul 2008
"Dean Wells (MVP)" <(E-Mail Removed)> wrote in message
news:egGL$(E-Mail Removed)...
> "Rich Pasco" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Suggestions are invited on the simplest and most reliable way
>> (in a BAT file command script) to check whether a command-line
>> parameter (e.g. %1 or %2) designates a valid drive letter (with
>> its colon, e.g. C: or D: )?
>>
>> - Rich

>
> Rich,
>
> Take a look at the post entitled 'Batch file to show Network drives',
> I believe you'll find relevant info. in there.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
>
>


Perhaps something like this depending on support for the binary of
course -

fsutil fsinfo drives | findstr /i "F:" && echo Valid. || echo Invalid.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l



 
Reply With Quote
 
Rich Pasco
Guest
Posts: n/a
 
      10th Jul 2008
Dean Wells (MVP) wrote:

>> Take a look at the post entitled 'Batch file to show Network drives',
>> I believe you'll find relevant info. in there.

>
> Perhaps something like this depending on support for the binary of
> course -
>
> fsutil fsinfo drives | findstr /i "F:" && echo Valid. || echo Invalid.


Thanks, Dean. Many of the solutions in that thread, including yours,
require fsutil, which doesn't seem to be present on my Windows 2000
system. Can I download it as an add-on, or is it limited to XP and
newer?

Learn about fsutil here
http://technet2.microsoft.com/window...d059f1033.mspx

Considering that I need to support Windows 2000, I may just stick with
my original solution, which does work under Windows 2000.

- Rich
 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      10th Jul 2008
"Rich Pasco" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dean Wells (MVP) wrote:
>
>>> Take a look at the post entitled 'Batch file to show Network
>>> drives',
>>> I believe you'll find relevant info. in there.

>>
>> Perhaps something like this depending on support for the binary of
>> course -
>>
>> fsutil fsinfo drives | findstr /i "F:" && echo Valid. || echo
>> Invalid.

>
> Thanks, Dean. Many of the solutions in that thread, including yours,
> require fsutil, which doesn't seem to be present on my Windows 2000
> system. Can I download it as an add-on, or is it limited to XP and
> newer?
>
> Learn about fsutil here
> http://technet2.microsoft.com/window...d059f1033.mspx
>
> Considering that I need to support Windows 2000, I may just stick with
> my original solution, which does work under Windows 2000.
>
> - Rich


Nod, fair comment, I confess my efforts regarding legacy-supportability
typically end at XP and 2K3.

Here's another hip-shot -

@echo off
set arg=%~1
set driveLETTER=%arg:~0,1%
if exist %driveLETTER::=%:\nul (
echo %driveLETTER::=%: is valid)
else (
echo %driveLETTER::=%: is invalid.
)

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l



 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a
 
      10th Jul 2008

"Dean Wells (MVP)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Rich Pasco" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Dean Wells (MVP) wrote:
>>
>>>> Take a look at the post entitled 'Batch file to show Network drives',
>>>> I believe you'll find relevant info. in there.
>>>
>>> Perhaps something like this depending on support for the binary of
>>> course -
>>>
>>> fsutil fsinfo drives | findstr /i "F:" && echo Valid. || echo Invalid.

>>
>> Thanks, Dean. Many of the solutions in that thread, including yours,
>> require fsutil, which doesn't seem to be present on my Windows 2000
>> system. Can I download it as an add-on, or is it limited to XP and
>> newer?
>>
>> Learn about fsutil here
>> http://technet2.microsoft.com/window...d059f1033.mspx
>>
>> Considering that I need to support Windows 2000, I may just stick with
>> my original solution, which does work under Windows 2000.
>>
>> - Rich

>
> Nod, fair comment, I confess my efforts regarding legacy-supportability
> typically end at XP and 2K3.
>
> Here's another hip-shot -
>
> @echo off
> set arg=%~1
> set driveLETTER=%arg:~0,1%
> if exist %driveLETTER::=%:\nul (
> echo %driveLETTER::=%: is valid)
> else (
> echo %driveLETTER::=%: is invalid.
> )
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l


See if this works at all for you:

@echo off

call:test C:
call:test c:
call:test c:d:fvfv\\wwwww
call:test "C:"
call:test "c:\"
call:test R:\dummy\asd.zxc
pause
goto:eof

:test
if /i "%~1" EQU "%~d1" (
echo/parameter IS a drive letter: "%~1"
) else (
echo/parameter is NOT a drive letter: "%~1"
)
goto:EOF

/Al


 
Reply With Quote
 
Rich Pasco
Guest
Posts: n/a
 
      10th Jul 2008
Al Dunbar wrote:

> See if this works at all for you:
>
> @echo off
>
> call:test C:
> call:test c:
> call:test c:d:fvfv\\wwwww
> call:test "C:"
> call:test "c:\"
> call:test R:\dummy\asd.zxc
> pause
> goto:eof
>
> :test
> if /i "%~1" EQU "%~d1" (
> echo/parameter IS a drive letter: "%~1"
> ) else (
> echo/parameter is NOT a drive letter: "%~1"
> )
> goto:EOF
>
> /Al


Hi Al, I like it. It is the same method as I used in my own example,
my second post in this thread.

- Rich
 
Reply With Quote
 
Esra Sdrawkcab
Guest
Posts: n/a
 
      10th Jul 2008

If running on an intel box, with debug in the path (or it could be
converted to ascii asm), this would do it:

@echo off
rem qdrvl.bat

echo E100 A0 5C 00 B4 4C CD 21> %temp%\qdrvl.dis
echo Rcx>> %temp%\qdrvl.dis
echo 7 >> %temp%\qdrvl.dis
echo w >> %temp%\qdrvl.dis
echo q >> %temp%\qdrvl.dis
echo create>%temp%\qdrvl.com
debug %temp%\qdrvl.com<%temp%\qdrvl.dis >nul
%temp%\qdrvl.com %1
if errorlevel 243 goto isnumbercolon
if errorlevel 1 echo valid drive
if not errorlevel 1 echo Not a valid drive
goto exit
:isnumbercolon
echo number followed by colon detected!
:exit
::del %temp%\qdrvl.com
del %temp%\qdrvl.dis


though it seems the com parser is a bit crude and allows $: and £:

(X-posted to amb)
 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a
 
      11th Jul 2008

"Rich Pasco" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Al Dunbar wrote:
>
>> See if this works at all for you:
>>
>> @echo off
>>
>> call:test C:
>> call:test c:
>> call:test c:d:fvfv\\wwwww
>> call:test "C:"
>> call:test "c:\"
>> call:test R:\dummy\asd.zxc
>> pause
>> goto:eof
>>
>> :test
>> if /i "%~1" EQU "%~d1" (
>> echo/parameter IS a drive letter: "%~1"
>> ) else (
>> echo/parameter is NOT a drive letter: "%~1"
>> )
>> goto:EOF
>>
>> /Al

>
> Hi Al, I like it. It is the same method as I used in my own example,
> my second post in this thread.


Sorry, I didn't recognize its similarity because you use a different IF
statement syntax.

/Al


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change drive letter -- the parameter is incorrect beetle Windows Vista Hardware 1 26th May 2008 04:41 PM
Assigned new drive letter to DVD drive. Reverts to old letter on reboot. Rob Windows XP General 6 6th Jul 2007 08:07 PM
Stupid SYSPREP assigns drive letter to partition with no previous letter bruneauhm@hotmail.com Windows XP Setup 0 21st Jun 2006 10:16 PM
USB Drive Letter Mapping - Conflict with network drive letter John Phillip Windows XP Hardware 2 4th Oct 2005 11:24 PM
Conflicting used space information when checking the drive property against marking all files and checking the marked file properties. elloko Windows XP Configuration 3 19th Dec 2004 05:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.