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 16:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How does batch processing detect USB drives? View 3,562 Replies 23
Original Poster Posted 2006-09-26 22:46 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
Searched for a long time, no result, here I hold the last hope, hope everyone can help me, thank you very much!

The general idea of this program is like this:
If there is a USB mobile device (format it and return "Format successful") Otherwise (
Return to execute again
)
Floor 2 Posted 2006-09-26 22:59 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Floor 3 Posted 2006-09-26 23:55 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Please be careful!!!

@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 %%1 in (!genre!) do (
fsutil fsinfo drivetype %%1 | findstr "移动" >nul 2>nul && if /i not "%%1"=="A:" echo Found removable storage device, may be USB drive=%%1
)
)
pause
Floor 4 Posted 2006-09-27 01:13 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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 external hard drives and USB flash drives still showed as fixed drives, which is a bit strange.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2006-09-27 02:07 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
Originally posted by pengfei at 2006-9-26 23:55:
Please use with caution!!!

@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
set genre=%%i
set genr ...



Could you please explain the meaning of this code segment?

Also, regarding the code for judging whether the formatting was successful, why doesn't it work?

format "USBHDD" /q /s /y
if errorlevel==0 (echo Formatting succeeded
) else (
echo Formatting failed
)

As expected, it should display "Formatting failed" if it didn't format normally, but every time it displays "Formatting succeeded".

[ Last edited by nvflash on 2006-9-27 at 02:14 ]
Floor 6 Posted 2006-09-27 08:18 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by namejm at 2006-9-27 01:13:
The code on 'Building 3' has conditional restrictions: it needs to be run under Windows XP and later systems with administrator privileges.
  However, when I tested it on my computer, the type display of the mobile hard drive and USB flash drive...

Me too
Floor 7 Posted 2006-09-27 09:14 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
Really depressed...

It works when I test it on my computer!
Attachments
1.jpg
Floor 8 Posted 2006-09-27 09:30 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Maybe some settings were changed, and then the keyword "move" can't be found. Please find the reason.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-09-27 09:32 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by pengfei at 2006-9-27 09:14:
Really depressed...

It works on my computer!

What's your icon arrangement like?
Floor 10 Posted 2006-09-27 09:37 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
Originally posted by pengfei at 2006-9-27 09:14:
Really depressed...

It works on my computer!


Then, if I want to format this USB flash drive now, what variable should I use to represent the drive letter?
Floor 11 Posted 2006-09-27 09:42 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
I'm not sure if the variable was used improperly. I made a change:

@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 "移动" >nul 2>nul && if /i not "%%a"=="A:" echo Found removable storage device, possibly USB flash drive=%%a
)
)
pause

The drive letter variable for formatting the USB flash drive is %%a

[ Last edited by pengfei on 2006-9-27 at 10:39 ]
Floor 12 Posted 2006-09-27 09:45 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
All are displaying drives
Attachments
aa.BMP
Floor 13 Posted 2006-09-27 09:48 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
19-year member
UID 58987
From 湖南.娄底
Status Offline
The brother upstairs shows that the command fsutil fsinfo drives is correct. Could it be that the pipe command after 'fsutil fsinfo drives^|find /v' didn't execute successfully.
Floor 14 Posted 2006-09-27 09:58 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
Originally posted by pengfei at 2006-9-27 09:42:
I don't know if it's an inappropriate variable use, I made a change:

@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%i in ('fsutil fsinfo drives^|find /v ""' ...

I express extremely high respect for the brother's help!
Floor 15 Posted 2006-09-27 10:33 ·  中国 重庆 合川区 电信
初级用户
Credits 126
Posts 38
Joined 2006-09-26 20:39
19-year member
UID 63726
Status Offline
But on my computer, it still can't be detected, nothing is displayed, so it pauses
Forum Jump: