China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 21:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Check the local disk and determine its type View 2,288 Replies 6
Original Poster Posted 2006-09-01 14:27 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
@echo off
setlocal enabledelayedexpansion
fsutil fsinfo drives>tmp.txt
for /f "skip=1 tokens=1,2 delims=驱动器 " %%a in ('find /v "" ^<tmp.txt') do (
if not defined aa (set aa=%%b) else set aa=!aa!;%%a
)
for %%i in (%aa%) do fsutil fsinfo drivetype %%i
del tmp.txt

Newcomer, please ask for advice from seniors...
Test environment WIN XP SP2
我今后在论坛的目标就是做个超级坏人!!!
Floor 2 Posted 2006-09-01 15:09 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Today I just found out that fsutil can be used for local information query, and the command is quite powerful.

This code can also be improved, without generating temporary files:

@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set aa=%%a
set aa=!aa:~-2!
for %%i in (!aa!) do fsutil fsinfo drivetype %%i
)
pause


In addition, the following problems exist in your code:

1. delims=驱动器 is incorrect for separating statements
2. if not defined aa (set aa=%%b) else set aa=!aa!;%%a, the format should be if not something (set1) else (set2), and the content of set is also written incorrectly: for example, if I add a sentence set aa=1 at the beginning, the problem immediately occurs;

[ Last edited by namejm on 2006-9-1 at 15:51 ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-09-01 17:23 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Learned a new command...
Floor 4 Posted 2006-09-01 17:25 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Take it, I'll use it soon these days
Floor 5 Posted 2006-09-01 22:03 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
fsutil fsinfo drives^|find /v "" This sentence is a bit strange. According to the general understanding, most people might not think of using find /v "" to filter, and just use fsutil fsinfo drives directly. However, if there is no statement after the pipe symbol in the code, it will only display the information of the first disk partition. I can't figure it out.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-09-03 00:05 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
It's not eerie, but because the result obtained by fsutil fsinfo drives has spaces in the middle, but it represents the function of carriage return or line feed, so you only get the information of the first partition.
我今后在论坛的目标就是做个超级坏人!!!
Floor 7 Posted 2007-05-23 17:53 ·  中国 广东 广州 黄埔区 电信
中级用户
★★
Credits 326
Posts 152
Joined 2007-05-04 06:16
19-year member
UID 87412
Gender Male
Status Offline
@echo off
:: code by 3742668 2006-12-6 CMD@XP
set /p x=Enter drive letter:
for /f "skip=1" %%i in ('wmic logicaldisk where "deviceid='%x%:'" get Description 2^>nul') do set type=%%i
if not defined type set type=This drive does not exist!
echo The type of %x%: drive is: %type%
pause>nul
goto :eof
Forum Jump: