标题: 如何判断驱动器的格式?
[打印本页]
作者: numbmeteor
时间: 2006-11-12 14:07
标题: 如何判断驱动器的格式?
rem 1.赋初值为0
for %%c 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 set test%%c=0
rem 2.如果盘符存在则相应变量值为1
for %%c 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 (if exist %%c: (set test%%c=1))
rem 3.如果是fat32格式则改相应变量值为2
for %%c 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 (CHKNTFS %%c:|FIND /I "FAT32"
IF %Errorlevel% equ 0 set test%%c=2)
rem 4.如果是ntfs格式则改相应变量值为3
for %%c 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 (CHKNTFS %%c:|FIND /I "NTFS"
IF %Errorlevel% equ 0 set test%%c=3)
rem 5.列出盘符相应变量最后的值以判断执行结果是否正确
for %%c 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 set test%%c
pause
我的分区是这样的,c,d,e盘是NTFS,f,g盘是FAT32,h盘是光驱,i盘是虚拟光驱,那么执行上面批处理后理想的结果应该是:testc=3,testd=3,teste=3,testf=2,testg=2,testh=1,testi=1,其它的盘都应是test(?)=0。
但事实上第三步执行完全部都为2,第四步执行无效,最后的结果都为2。而我如果把|||CHKNTFS %c:|FIND /I "NTFS" IF %Errorlevel% equ 0 set test%%c=3|||这两条命令直接在CMD中运行结果是完全正确的,所有我以为是因为把它们放在了for命令里使用而造成的,可能errorlevel返回值并不是find的返回值了,我这么想。
请各位大师们指点指点吧,小弟在此谢过了
作者: lxmxn
时间: 2006-11-13 11:37
试试下面这个代码,没有测试。
我的环境是:Windows xp sp1 @ CMD Shell
@echo off&&setlocal enabledelayedexpansion
for %%c 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 (
set test%%c=0
if exist %%c: (
set test%%c=1
chkntfs %%c:|find /i "fat32" > nul && (
set test%%c=2) || chkntfs %%c: | find /i "ntfs" >nul && (
set test%%c=3)
echo %%c: 盘的类型 !test%%c!..
))
pause
作者: numbmeteor
时间: 2006-11-15 02:52
标题: 谢谢lxmxn了
经测试确实可行,但我仍有迷团未解,想知道第三步的if errorlevel那里为什么不能得到正确的结果?