|
nvflash
初级用户
 
积分 126
发帖 38
注册 2006-9-26
状态 离线
|
『楼 主』:
批处理怎样检测U盘?
使用 LLM 解释/回答一下
寻求N久,未果,在此抱最后希望,望大家帮助小弟一把,不甚感谢!
这个程序我的思路大概是这样的:
如果 有USB移动设备 (将其格式化,并返回“格式化成功”
) 否则 (
返回重新执行
)
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
)
|
|
2006-9-26 22:46 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
|
2006-9-26 22:59 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
请慎用!!!
@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 找到可移动存储设备, 可能为U盘=%%1
)
)
pause
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
|
|
2006-9-26 23:55 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
『第 3 楼』的代码有条件限制的:要在XP及其之后的系统下,以管理员权限运行。
不过在我的机子上测试的时候,移动硬盘和U盘的类型显示的依然是固定驱动器字样,有点奇怪。
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没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 01:13 |
|
|
nvflash
初级用户
 
积分 126
发帖 38
注册 2006-9-26
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-26 23:55:
请慎用!!!
@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 ...
麻烦解释一下此段代码的意思好吗?
另外,关于判断是否格式化成功这段代码,为什么没用呢?
format "USBHDD" /q /s /y
if errorlevel==0 (echo 格式化成功
) else (
echo 格式化失败
)
按预计是没有正常格式化就显示“格式化失败”,但每次却都是显示的"格式化成功"。
Last edited by nvflash on 2006-9-27 at 02:14 ]
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 ]
|
|
2006-9-27 02:07 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2006-9-27 01:13:
『第 3 楼』的代码有条件限制的:要在XP及其之后的系统下,以管理员权限运行。
不过在我的机子上测试的时候,移动硬盘和U盘的类型显示 ...
我的也是这样
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
|
|
2006-9-27 08:18 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
真郁闷...
在我电脑上测试行啊!
Really depressed...
It works when I test it on my computer!
附件
1: 1.jpg (2006-9-27 09:14, 37.51 KiB, 下载附件所需积分 1 点
,下载次数: 1)
|
|
2006-9-27 09:14 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
可能是什么地方设置改动了之后就出现找不到 "移动" 这个关键词了,请各位查找一下原因吧。
Maybe some settings were changed, and then the keyword "move" can't be found. Please find the reason.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-27 09:30 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:14:
真郁闷...
在我电脑上测试行啊!
你的排列图标是怎么样的?
Originally posted by pengfei at 2006-9-27 09:14:
Really depressed...
It works on my computer!
What's your icon arrangement like?
|
|
2006-9-27 09:32 |
|
|
nvflash
初级用户
 
积分 126
发帖 38
注册 2006-9-26
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:14:
真郁闷...
在我电脑上测试行啊!
那么,如果我现在要格式化这个U盘,应该用什么变量来代表盘符呢?
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?
|
|
2006-9-27 09:37 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
不知道是不是变量用的不妥, 改了一下:
@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 找到可移动存储设备, 可能为U盘=%%a
)
)
pause
格式化U盘的盘符变量为 %%a
Last edited by pengfei on 2006-9-27 at 10:39 ]
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 ]
|
|
2006-9-27 09:42 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
全是显示 驱动器
All are displaying drives
附件
1: aa.BMP (2006-9-27 09:45, 52.87 KiB, 下载附件所需积分 1 点
,下载次数: 1)
|
|
2006-9-27 09:45 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
楼上兄弟运行 fsutil fsinfo drives 命令显示没错, 难道'fsutil fsinfo drives^|find /v 后面这个管道命令没有成功执行.
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.
|
|
2006-9-27 09:48 |
|
|
nvflash
初级用户
 
积分 126
发帖 38
注册 2006-9-26
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by pengfei at 2006-9-27 09:42:
不知道是不是变量用的不妥, 改了一下:
@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2 delims=\" %%i in ('fsutil fsinfo drives^|find /v ""' ...
对于仁兄的帮助表示无比崇高的敬意!
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!
|
|
2006-9-27 09:58 |
|
|
nvflash
初级用户
 
积分 126
发帖 38
注册 2006-9-26
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
但是,在我的电脑上还是检测不到,什么也不显示,就暂停了
But on my computer, it still can't be detected, nothing is displayed, so it pauses
|
|
2006-9-27 10:33 |
|