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 06:37
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to detect the number of partitions in the hard disk using batch processing. View 1,726 Replies 12
Original Poster Posted 2007-03-12 03:37 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Make a small program to do Ghost backup and restore under Win, which needs to detect the number of partitions in the hard disk (when a USB flash drive is inserted, it does not affect the detection result), so that the backup file can be automatically stored in the last partition. I know it can be done with Ghost32.exe, but I think it should be simpler to do it with batch processing. How to do it?

[ Last edited by axi on 2007-3-20 at 09:17 PM ]
Floor 2 Posted 2007-03-12 05:19 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
@echo off
set num=
for %%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 (
fsutil fsinfo drivetype %%i: | find /i "Fixed" >nul 2>nul && set /a num+=1
)
echo There are %num% local disk partitions.
pause>nul
Floor 3 Posted 2007-03-12 05:38 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
Try this
@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 /f "tokens=1 " %%i in ('fsutil fsinfo drivetype !aa! ^|find "Fixed"') do @echo %%i
)
pause
Floor 4 Posted 2007-03-12 10:31 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
The method of htysm is okay, but after inserting the USB flash drive, an extra partition is detected. How to solve this?
Floor 5 Posted 2007-03-12 10:32 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

Wmic LogicalDisk get caption,description,freespace
Floor 6 Posted 2007-03-12 10:35 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
The method of qingfushuan is to obtain the drive letters of each partition, but it also lists the USB flash drive. Also, is there a way to solve this?
Floor 7 Posted 2007-03-12 12:31 ·  中国 新疆 塔城地区 电信
中级用户
★★
Credits 354
Posts 83
Joined 2003-03-23 00:00
23-year member
UID 1232
Gender Male
Status Offline
Floor 8 Posted 2007-03-12 13:21 ·  中国 黑龙江 哈尔滨 电信
高级用户
★★★
Credits 760
Posts 357
Joined 2005-10-10 22:33
20-year member
UID 43332
Status Offline
Old Ge's stuff!
Hehe
Floor 9 Posted 2007-03-12 21:34 ·  中国 河南 开封 教育网
中级用户
★★
Credits 214
Posts 94
Joined 2007-01-11 10:39
19-year member
UID 76165
Gender Male
Status Offline
There is a drvtypes that will display all existing drive letters and related information. Batch processing can judge the information and exclude USB drives A, B, RAM disks, and various optical drive disks.
Floor 10 Posted 2007-03-12 22:51 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
The code on the 2nd floor won't display the USB flash drive. Unless it's a mobile hard drive.
Floor 11 Posted 2007-03-13 01:00 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
Originally posted by axi at 2007-3-11 09:35 PM:
The method of qingfushuan is to obtain the drive letters of each partition, but it also lists the USB flash drive. Also, is there a way to solve this?



『13th floor』:

Can the following be tried?

@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 /f "tokens=1 " %%i in ('fsutil fsinfo drivetype !aa! ^|findstr /i "fixed removable"') do @echo %%i
)
pause
Floor 12 Posted 2007-03-13 01:25 ·  中国 江苏 连云港 电信
高级用户
★★★
前进者
Credits 641
Posts 303
Joined 2007-01-10 02:57
19-year member
UID 76009
Gender Male
Status Offline
wmic logicaldisk where(drivetype='3') get caption
我相信总有一天,总会遇到一个人可以相濡以沫、相吻以湿!
Floor 13 Posted 2007-03-13 01:48 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
The method on floor 13 has been tried, but it still doesn't work. My USB flash drive is regarded as a mobile hard disk.
Forum Jump: