|
youtube2046
新手上路
积分 15
发帖 9
注册 2008-8-23 来自 Beijing
状态 离线
|
『楼 主』:
如何提取出最后一行中的特定字符?
我想通过GDISK生成的磁盘报告,来确定一块硬盘的最后一个盘符, 以及在GHOST中备份到最后一个分区时,应使用的盘符数字.
本例中,希望提取出最后一行的 F: 赋给变量driveletter, 提取出 5 赋给变量drivenum.
磁盘报告如下:
Disk Partitions Cylinders Heads Sectors Mbytes Model
2 5 30401 255 63 238475.2 ST3250820AS
Partition Status Type Volume Label Mbytes System Usage
C: 1 A PRIMARY System 25603.6 NTFS/HPFS 11%
2 EXTENDED 212869.1 89%
D: 3 LOGICAL Temp 59263.2 NTFS/HPFS 25%
E: 4 LOGICAL Work 51199.3 NTFS/HPFS 21%
F: 5 LOGICAL Study 102406.5 NTFS/HPFS 43%
当然不同的硬盘生成的磁盘报告不同,比如有的可能是4个盘符有的可能是7个盘符等.
望高手指教.
[ Last edited by youtube2046 on 2009-1-24 at 22:02 ]
|
|
2009-1-24 21:46 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
2 楼』:
@echo off
for /f "tokens=1,2 delims=: " %%i in (1.txt) do (
set dl=%%i
set dn=%%j
)
echo 盘符为:%dl% 数字表示为:%dn%
pause
|
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2009-1-24 22:50 |
|
|
newxso
初级用户
l i u s s
积分 73
发帖 101
注册 2008-9-17 来自 GZ
状态 离线
|
『第
3 楼』:
你应该说明是在XP下还是在纯DOS下,在XP下处理这样的内容很容易,在纯DOS下没有第三方工具就麻烦点。以下是我以前应用在启动盘中的批处理(纯DOS下):
@echo off
set hdd=
set partn=
set zpartn=
set ntpartn=
cls
echo 正在检测硬盘, 请稍等...
gdisk >dk
find " " /c dk >dkn
rem 硬盘数的检测(不超过4个)
:4dk
find "5" dkn >nul
if errorlevel 1 goto 3dk
set hdd=4
goto 1dkpar
:3dk
find "4" dkn >nul
if errorlevel 1 goto 2dk
set hdd=3
goto 1dkpar
:2dk
find "3" dkn >nul
if errorlevel 1 goto 1dk
set hdd=2
goto 1dkpar
:1dk
find "2" dkn >nul
if errorlevel 1 goto 0dk
set hdd=1
goto 1dkpar
:0dk
set hdd=0
goto ext
rem 检测分区数的依据:(利用find.exe检测文件里含有特有字符的行数)
rem 命令: gdisk 1 可显示第1硬盘的分区信息
rem 命令: gdisk 2 可显示第2硬盘的分区信息
rem 命令: gdisk 1 >pt 把第1硬盘分区信息创建到pt文本文件里
rem 某些硬盘在作为从盘用时,只划分成逻辑分区,没划分出主分区
rem 在有1个主分区时,逻辑分区数加1等于实际的分区数
rem 在没有主分区时,逻辑分区数就是实际的分区数
rem 第1硬盘中的分区数检测(不超过9个)
:1dkpar
gdisk 1 >pt
find "No partitions defined" pt >nul
if not errorlevel 1 goto nopar
find "LOGICAL" /c pt >ptn
goto 1par
rem 仅有1主分区(没有逻辑分区)
:1par
find "PRIMARY" pt >nul
if errorlevel 1 goto 1logpar
find "LOGICAL" pt >nul
if not errorlevel 1 goto 2par
set partn=1
goto 2dkpar
rem 仅有1个分区(有1个逻辑分区和没有主分区)
:1logpar
find "1" ptn >nul
if errorlevel 1 goto 2logpar
set partn=1
goto 2dkpar
rem 仅有2个分区(有2个逻辑分区和没有主分区)
:2logpar
find "2" ptn >nul
if errorlevel 1 goto 3logpar
set partn=2
goto 2dkpar
:3logpar
find "3" ptn >nul
if errorlevel 1 goto 4logpar
set partn=3
goto 2dkpar
:4logpar
find "4" ptn >nul
if errorlevel 1 goto 5logpar
set partn=4
goto 2dkpar
:5logpar
find "5" ptn >nul
if errorlevel 1 goto 6logpar
set partn=5
goto 2dkpar
:6logpar
find "6" ptn >nul
if errorlevel 1 goto 7logpar
set partn=6
goto 2dkpar
:7logpar
find "7" ptn >nul
if errorlevel 1 goto 8logpar
set partn=7
goto 2dkpar
:8logpar
find "8" ptn >nul
if errorlevel 1 goto 9logpar
set partn=8
goto 2dkpar
:9logpar
find "9" ptn >nul
if errorlevel 1 goto err
set partn=9
goto 2dkpar
rem 仅有2个分区(有1个逻辑分区和1个主分区)
:2par
find "1" ptn >nul
if errorlevel 1 goto 3par
set partn=2
goto 2dkpar
rem 仅有3个分区(有2个逻辑分区和1个主分区)
:3par
find "2" ptn >nul
if errorlevel 1 goto 4par
set partn=3
goto 2dkpar
:4par
find "3" ptn >nul
if errorlevel 1 goto 5par
set partn=4
goto 2dkpar
:5par
find "4" ptn >nul
if errorlevel 1 goto 6par
set partn=5
goto 2dkpar
:6par
find "5" ptn >nul
if errorlevel 1 goto 7par
set partn=6
goto 2dkpar
:7par
find "6" ptn >nul
if errorlevel 1 goto 8par
set partn=7
goto 2dkpar
:8par
find "7" ptn >nul
if errorlevel 1 goto 9par
set partn=8
goto 2dkpar
:9par
find "8" ptn >nul
if errorlevel 1 goto err
set partn=9
goto 2dkpar
:err
set partn=?
goto 2dkpar
rem 第1硬盘中没有分区
:nopar
set partn=0
goto 2dkpar
rem 第2硬盘分区数检测(不超过9个)
:2dkpar
if %hdd%==1 goto ntpar
gdisk 2 >zpt
find "No partitions defined" zpt >nul
if not errorlevel 1 goto znopar
find "LOGICAL" /c zpt >zptn
goto z1par
:z1par
find "PRIMARY" zpt >nul
if errorlevel 1 goto z1logpar
find "LOGICAL" zpt >nul
if not errorlevel 1 goto z2par
set zpartn=1
goto ntpar
:z1logpar
find "1" zptn >nul
if errorlevel 1 goto z2logpar
set zpartn=1
goto ntpar
:z2logpar
find "2" zptn >nul
if errorlevel 1 goto z3logpar
set zpartn=2
goto ntpar
:z3logpar
find "3" zptn >nul
if errorlevel 1 goto z4logpar
set zpartn=3
goto ntpar
:z4logpar
find "4" zptn >nul
if errorlevel 1 goto z5logpar
set zpartn=4
goto ntpar
:z5logpar
find "5" zptn >nul
if errorlevel 1 goto z6logpar
set zpartn=5
goto ntpar
:z6logpar
find "6" zptn >nul
if errorlevel 1 goto z7logpar
set zpartn=6
goto ntpar
:z7logpar
find "7" zptn >nul
if errorlevel 1 goto z8logpar
set zpartn=7
goto ntpar
:z8logpar
find "8" zptn >nul
if errorlevel 1 goto z9logpar
set zpartn=8
goto ntpar
:z9logpar
find "9" zptn >nul
if errorlevel 1 goto zerr
set zpartn=9
goto ntpar
:z2par
find "1" zptn >nul
if errorlevel 1 goto z3par
set zpartn=2
goto ntpar
:z3par
find "2" zptn >nul
if errorlevel 1 goto z4par
set zpartn=3
goto ntpar
:z4par
find "3" zptn >nul
if errorlevel 1 goto z5par
set zpartn=4
goto ntpar
:z5par
find "4" zptn >nul
if errorlevel 1 goto z6par
set zpartn=5
goto ntpar
:z6par
find "5" zptn >nul
if errorlevel 1 goto z7par
set zpartn=6
goto ntpar
:z7par
find "6" zptn >nul
if errorlevel 1 goto z8par
set zpartn=7
goto ntpar
:z8par
find "7" zptn >nul
if errorlevel 1 goto z9par
set zpartn=8
goto ntpar
:z9par
find "8" zptn >nul
if errorlevel 1 goto zerr
set zpartn=9
goto ntpar
:zerr
set zpartn=?
goto ntpar
:znopar
set zpartn=0
goto ntpar
rem 以下是对NTFS分区数的检测(两个硬盘总NTFS分区数不超过9个)
:ntpar
set ntpartn=0
type pt >ntpt
if exist zpt type zpt >>ntpt
find "NTFS" /c ntpt >ntptn
:1ntptn
find "1" ntptn >nul
if errorlevel 1 goto 2ntptn
set ntpartn=1
goto ext
:2ntptn
find "2" ntptn >nul
if errorlevel 1 goto 3ntptn
set ntpartn=2
goto ext
:3ntptn
find "3" ntptn >nul
if errorlevel 1 goto 4ntptn
set ntpartn=3
goto ext
:4ntptn
find "4" ntptn >nul
if errorlevel 1 goto 5ntptn
set ntpartn=4
goto ext
:5ntptn
find "5" ntptn >nul
if errorlevel 1 goto 6ntptn
set ntpartn=5
goto ext
:6ntptn
find "6" ntptn >nul
if errorlevel 1 goto 7ntptn
set ntpartn=6
goto ext
:7ntptn
find "7" ntptn >nul
if errorlevel 1 goto 8ntptn
set ntpartn=7
goto ext
:8ntptn
find "8" ntptn >nul
if errorlevel 1 goto 9ntptn
set ntpartn=8
goto ext
:9ntptn
find "9" ntptn >nul
if errorlevel 1 goto ext
set ntpartn=9
goto ext
rem -------------------------------------------------------------------------------
rem 硬盘检测程序说明
rem -------------------------------------------------------------------------------
rem
rem 本程序是依据gdisk程序的检测硬盘功能,利用命令">***把产生的信息创建到一个文本文件
rem 中,并用程序find来查找其中的关键字符串,以达到分区数的检测. 除可利用gdisk来检测硬
rem 盘外,也可用ghost.exe程序来检测硬盘,命令行为:ghost -dd >nul,生成的分区信息保存在
rem 当前目录下的ghststat.txt中,可以用find程序来查找其中的关键字符串来确定分区数.
rem
rem 注意: 请在本程序(FINDHDD.BAT)同一目录下放置: gdisk.exe和find.exe程序.
rem 本程序适合含主分区在内的1-9个分区检测,或不含主分区的1-9个逻辑分区检测.
rem 如果分区数超过9个时,本程序会出错,所得的partn和zpartn值将不准确.
rem
rem 变量hdd的值为1-4,表示硬盘数为1-4个,hdd为0时无硬盘.
rem 变量partn的值为1-9,表示第1硬盘有1-9个分区,partn为0表示无分区.
rem 变量zpartn的值为1-9,表示第2硬盘有1-9个分区,zpartn为0表示无分区.
rem 变量partn和zpartn等于?时,表示分数已超过9个.具体分区数请在主菜单下按P键查看.
rem 变量ntpartn等于1-9时,表示存在NTFS分区数为1-9个,ntpartn为0时表示没有NTFS分区.
rem -------------------------------------------------------------------------------
rem 删除临时生成的文本文件并退出
:ext
if exist dk del dk
if exist dkn del dkn
if exist ntpt del ntpt
if exist ntptn del ntptn
if exist pt del pt
if exist ptn del ptn
if exist zpt del zpt
if exist zptn del zptn
[ Last edited by newxso on 2009-1-24 at 23:04 ]
|
|
2009-1-24 22:56 |
|
|
newxso
初级用户
l i u s s
积分 73
发帖 101
注册 2008-9-17 来自 GZ
状态 离线
|
『第
4 楼』:
其实用 ghost.exe 也可以完成分区数检测,获取最后分区(ghost8.3):
@echo off
rem 注意:在本程序同目录下必须有ghost.exe和find.exe两个程序,并启动了汉字系统(如果想显示中文)
rem hdd=1-2表示有1-2个硬盘, hdd=0表示没有硬盘(或硬盘数超过2个)
rem partn=1-9表示第1硬盘有1-9个分区, partn=0表示第1硬盘中没有分区, partn=n未知分区数
rem zpartn=1-9表示第2硬盘有1-9个分区, zpartn=0表示第2硬盘中没有分区, zpartn=n未知分区数
rem ntpartn=1-9表示第1和第2硬盘中总共有1-9个NTFS分区, ntpartn=0表示没有NTFS分区存在
set hdd=
set partn=
set zpartn=
set ntpartn=
rem call tway.bat
cls
echo 正在检测硬盘, 请稍等...
ghost -dd >nul
rem 检测第1硬盘分区数(最多9个)
:1hddp
find "Key[1] 1" ghststat.txt >nul
if errorlevel 1 goto nohdd
set hdd=1
find "Key[1] 1" /c ghststat.txt >1ght
:0pt
find "0" 1ght >nul
if errorlevel 1 goto 1pt
set partn=0
goto 2hddp
:1pt
find "1" 1ght >nul
if errorlevel 1 goto 2pt
set partn=1
goto 2hddp
:2pt
find "2" 1ght >nul
if errorlevel 1 goto 3pt
set partn=2
goto 2hddp
:3pt
find "3" 1ght >nul
if errorlevel 1 goto 4pt
set partn=3
goto 2hddp
:4pt
find "4" 1ght >nul
if errorlevel 1 goto 5pt
set partn=4
goto 2hddp
:5pt
find "5" 1ght >nul
if errorlevel 1 goto 6pt
set partn=5
goto 2hddp
:6pt
find "6" 1ght >nul
if errorlevel 1 goto 7pt
set partn=6
goto 2hddp
:7pt
find "7" 1ght >nul
if errorlevel 1 goto 8pt
set partn=7
goto 2hddp
:8pt
find "8" 1ght >nul
if errorlevel 1 goto 9pt
set partn=8
goto 2hddp
:9pt
find "9" 1ght >nul
if errorlevel 1 goto err
set partn=9
goto 2hddp
:err
set partn=n
goto 2hddp
rem 检测第2硬盘分区数(最多9个)
:2hddp
find "Key[1] 2" ghststat.txt >nul
if errorlevel 1 goto ntpt
set hdd=2
find "Key[1] 2" /c ghststat.txt >2ght
:z0pt
find "0" 2ght >nul
if errorlevel 1 goto z1pt
set zpartn=0
goto ntpt
:z1pt
find "1" 2ght >nul
if errorlevel 1 goto z2pt
set zpartn=1
goto ntpt
:z2pt
find "2" 2ght >nul
if errorlevel 1 goto z3pt
set zpartn=2
goto ntpt
:z3pt
find "3" 2ght >nul
if errorlevel 1 goto z4pt
set zpartn=3
goto ntpt
:z4pt
find "4" 2ght >nul
if errorlevel 1 goto z5pt
set zpartn=4
goto ntpt
:z5pt
find "5" 2ht >nul
if errorlevel 1 goto z6pt
set zpartn=5
goto ntpt
:z6pt
find "6" 2ght >nul
if errorlevel 1 goto z7pt
set zpartn=6
goto ntpt
:z7pt
find "7" 2ght >nul
if errorlevel 1 goto z8pt
set zpartn=7
goto ntpt
:z8pt
find "8" 2ght >nul
if errorlevel 1 goto z9pt
set zpartn=8
goto ntpt
:z9pt
find "9" 2ght >nul
if errorlevel 1 goto zerr
set zpartn=9
goto ntpt
:zerr
set zpartn=n
goto ntpt
rem 检测NTFS分区个数(9个以内,如果有2个硬盘,则此值为2硬盘的总NTFS分区数)
:ntpt
find "Type NTFS" /c ghststat.txt >3ght
:0nt
find "0" 3ght >nul
if errorlevel 1 goto 1nt
set ntpartn=0
goto exit
:1nt
find "1" 3ght >nul
if errorlevel 1 goto 2nt
set ntpartn=1
goto exit
:2nt
find "2" 3ght >nul
if errorlevel 1 goto 3nt
set ntpartn=2
goto exit
:3nt
find "3" 3ght >nul
if errorlevel 1 goto 4nt
set ntpartn=3
goto exit
:4nt
find "4" 3ght >nul
if errorlevel 1 goto 5nt
set ntpartn=4
goto exit
:5nt
find "5" 3ght >nul
if errorlevel 1 goto 6nt
set ntpartn=5
goto exit
:6nt
find "6" 3ght >nul
if errorlevel 1 goto 7nt
set ntpartn=6
goto exit
:7nt
find "7" 3ght >nul
if errorlevel 1 goto 8nt
set ntpartn=7
goto exit
:8nt
find "8" 3ght >nul
if errorlevel 1 goto 9nt
set ntpartn=8
goto exit
:9nt
find "9" 3ght >nul
if errorlevel 1 goto nterr
set ntpartn=9
goto exit
:nterr
set ntpartn=n
goto exit
:exit
if exist 1ght del 1ght
if exist 2ght del 2ght
if exist 3ght del 3ght
rem 显示检测结果
cls
if %hdd%==2 goto exit_
echo 检测完成! 产生3个变量: hdd / partn / ntpartn
echo ----------------------------------------------
echo.
echo 硬盘数(hdd): %hdd%
echo 分区数(partn): %partn%
echo NTFS分区数(ntpartn): %ntpartn%
echo.
wait 5
goto end
:exit_
echo 检测完成! 产生4个变量: hdd / partn / zpartn / ntpartn
echo -------------------------------------------------------
echo.
echo 硬盘数(hdd): %hdd%
echo 第1硬盘分区数(partn): %partn%
echo 第2硬盘分区数(zpartn): %zpartn%
echo NTFS分区总数(ntpartn): %ntpartn%
echo.
wait 6
goto end
:nohdd
set hdd=0
cls
echo.
echo 你的机器中没有硬盘!
echo.
wait 6
:end
[ Last edited by newxso on 2009-1-24 at 23:09 ]
|
|
2009-1-24 23:02 |
|
|
youtube2046
新手上路
积分 15
发帖 9
注册 2008-8-23 来自 Beijing
状态 离线
|
『第
5 楼』:
Quote: | Originally posted by newxso at 2009-1-24 10:56 PM:
你应该说明是在XP下还是在纯DOS下,在XP下处理这样的内容很容易,在纯DOS下没有第三方工具就麻烦点。以下是我以前应用在启动盘中的批处理(纯DOS下 ... |
|
我以为有GDisk 生成的磁盘报告文件,放到虚拟盘里,就可以越过读取硬盘内容的必要,这样可以避开NTFS带来的麻烦。
我希望在XP和纯DOS下分别实现。如果说在XP下很容易,也希望贴出XP下的实现方法。
|
|
2009-1-25 12:01 |
|
|
youtube2046
新手上路
积分 15
发帖 9
注册 2008-8-23 来自 Beijing
状态 离线
|
『第
6 楼』:
Quote: | Originally posted by slore at 2009-1-24 10:50 PM:
@echo off
for /f "tokens=1,2 delims=: " %%i in (1.txt) do (
set dl=%%i
set dn=%%j
)
echo 盘符为:%dl% 数字表示为:%dn%
pause |
|
在XP实现这个代码很好。但是在纯DOS下可以也这么简便就实现吗?
|
|
2009-1-25 12:26 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
7 楼』:
不能……
|
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore |
|
2009-1-25 12:57 |
|
|