中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 16:59
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Closed] How to detect the number of partitions in the hard disk using batch processing.
Printable Version  1,814 / 12
Floor1 axi Posted 2007-03-12 03:37
中级用户 Posts 93 Credits 238 From GZ
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 ]
Floor2 htysm Posted 2007-03-12 05:19
高级用户 Posts 415 Credits 866
@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
Floor3 qingfushuan Posted 2007-03-12 05:38
高级用户 Posts 327 Credits 502
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
Floor4 axi Posted 2007-03-12 10:31
中级用户 Posts 93 Credits 238 From GZ
The method of htysm is okay, but after inserting the USB flash drive, an extra partition is detected. How to solve this?
Floor5 lxmxn Posted 2007-03-12 10:32
版主 Posts 4,938 Credits 11,386
Floor6 axi Posted 2007-03-12 10:35
中级用户 Posts 93 Credits 238 From GZ
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?
Floor7 ww111222 Posted 2007-03-12 12:31
中级用户 Posts 83 Credits 354
Floor8 0451lym Posted 2007-03-12 13:21
高级用户 Posts 357 Credits 760
Old Ge's stuff!
Hehe
Floor9 llztt1 Posted 2007-03-12 21:34
中级用户 Posts 94 Credits 214
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.
Floor10 htysm Posted 2007-03-12 22:51
高级用户 Posts 415 Credits 866
The code on the 2nd floor won't display the USB flash drive. Unless it's a mobile hard drive.
Floor11 qingfushuan Posted 2007-03-13 01:00
高级用户 Posts 327 Credits 502
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
Floor12 oilio Posted 2007-03-13 01:25
高级用户 Posts 303 Credits 641
wmic logicaldisk where(drivetype='3') get caption
Floor13 axi Posted 2007-03-13 01:48
中级用户 Posts 93 Credits 238 From GZ
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023