![]() |
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-09-26 13:01 |
47,813 topics / 349,918 posts / today 0 new / 48,275 members |
| DOS批处理 & 脚本技术(批处理室) » How does batch processing detect USB drives? |
| Printable Version 3,858 / 23 |
| Floor16 pengfei | Posted 2006-09-27 10:35 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 ] |
|
| Floor17 nvflash | Posted 2006-09-27 22:13 |
| 初级用户 Posts 38 Credits 126 | |
|
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 ) ) |
|
| Floor18 9527 | Posted 2006-09-27 22:54 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
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!!! |
|
| Floor19 pengfei | Posted 2006-09-28 00:10 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 ] |
|
| Floor20 pengfei | Posted 2006-09-28 00:12 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 ] |
|
| Floor21 nvflash | Posted 2006-09-28 10:58 |
| 初级用户 Posts 38 Credits 126 | |
|
There's nothing important left. Thanks for the brother's help!
|
|
| Floor22 3742668 | Posted 2006-09-29 02:10 |
| 荣誉版主 Posts 718 Credits 2,013 | |
| Floor23 uemuem | Posted 2007-12-04 12:40 |
| 初级用户 Posts 68 Credits 153 From 上海 | |
Originally posted by namejm at 2006-9-27 01:13: Encountered the same problem. The external hard drive is not known how to judge: it all shows as fixed drives |
|
| Floor24 huahua0919 | Posted 2007-12-04 14:19 |
| 银牌会员 Posts 780 Credits 1,608 | |
Originally posted by nvflash at 2006-9-27 09:58 AM: Why is tokens=1,2 ---- tokens=1 Why use!genre:~2! ---- directly discard It feels a bit redundant |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |