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-07-07 14:49
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How does batch processing detect USB drives? View 3,554 Replies 23
Floor 16 Posted 2006-09-27 10:35 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
I'm sorry, a variable had an error and has been corrected. Please re-test the code on floor 11!

[ Last edited by pengfei on 2006-9-27 at 10:40 ]
Floor 17 Posted 2006-09-27 22:13 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
Boss, I added format %%a, but it formatted the E drive! This is how I added it

setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
set genre=%%i
set genre=!genre:~-2!
for %%a in (!genre!) do (
fsutil fsinfo drivetype %%a | findstr "移动" >nul 2>nul && if /i not "%%a"=="A:" echo Found removable storage device, possibly USB drive=%%a
format %%a /q /x /y
)
)
Floor 18 Posted 2006-09-27 22:54 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
Is the problem not this complicated???
@echo off
for /f "delims=" %%a in ('fsutil fsinfo drives^|find /v ""') do set a=%%a
fsutil fsinfo drivetype %a%|find "Removable" >nul&&goto :format||echo Sorry, no removable drive found!&&goto:eof
:format
format %a% /fs:fat32 /q
echo Format completed!!!
我今后在论坛的目标就是做个超级坏人!!!
Floor 19 Posted 2006-09-28 00:10 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
I'm really sorry! It's all my fault for not making it clear. Formatting drive E is already the lesser of two evils. The owner added the formatting code in the wrong place. Not doing a full disk format is already lucky.

Your formatting was added inside the inner loop. The %%a loop variable lists all drive letters on the hard drive. So you must be careful when using it!!!

The code is modified as follows:
@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
set genre=%%i
set genre=!genre:~-2!
for %%a in (!genre!) do (
fsutil fsinfo drivetype %%a | findstr "Removable" >nul 2>nul && if /i not "%%a"=="A:" (
set drive=%%a
echo Found removable storage device, drive letter is %%a
call :go
)
)
)
cls
echo All drive letters have been detected!
pause
exit

:go
echo.
set /p choice=Please choose (y=format this drive n=skip):
if /i "%choice%"=="y" goto begin
if /i "%choice%"=="n" goto :eof
goto go
:begin
echo format !drive! /q /x /y
echo Formatting completed!
pause
:eof

For safety, the formatting code is changed to display it. After testing, if there are no problems, remove the previous echo
echo format !drive! /q /x /y

[ Last edited by pengfei on 2006-9-28 at 00:30 ]
Floor 20 Posted 2006-09-28 00:12 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Please be extremely careful. Before testing this code, first change format to echo.

Deeply apologize for the loss caused to the owner by formatting the E drive. If there are important data on the E drive, please leave me a message. I have a data recovery software here, which may be able to recover some losses.

[ Last edited by pengfei on 2006-9-28 at 00:48 ]
Floor 21 Posted 2006-09-28 10:58 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
There's nothing important left. Thanks for the brother's help!
Floor 22 Posted 2006-09-29 02:10 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Floor 23 Posted 2007-12-04 12:40 ·  中国 上海 联通
初级用户
★★
Credits 153
Posts 68
Joined 2006-10-12 22:25
19-year member
UID 65507
From 上海
Status Offline
Originally posted by namejm at 2006-9-27 01:13:
The code in 'Building 3' has conditional restrictions: it needs to be run with administrator privileges under Windows XP and later systems.
However, when I tested it on my computer, the types of the external hard drive and USB flash drive still showed as fixed drives, which is a bit strange.


Encountered the same problem. The external hard drive is not known how to judge: it all shows as fixed drives
个人主页-找餐厅:http://www.canting.cc
Floor 24 Posted 2007-12-04 14:19 ·  中国 江苏 苏州 移动
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Originally posted by nvflash at 2006-9-27 09:58 AM:

I express my highest respect for your help!

Why is tokens=1,2 ---- tokens=1
Why use!genre:~2! ---- directly discard
It feels a bit redundant
Forum Jump: