找回密码
 加入
搜索
查看: 14658|回复: 30

[效率算法] 求正则表达式,dsptw生成的文本到listview【已解决】

 火.. [复制链接]
发表于 2010-6-6 08:40:54 | 显示全部楼层 |阅读模式
本帖最后由 23070205 于 2010-6-6 16:41 编辑
No.  Dr Tag FileSystem     Volume      Act StartPos   Sectors    MBytes FreeMB
1:1  C: Log HPFS/NTFS      IDE-1           16128      41929587   20473  1
1:2  D: Log HPFS/NTFS      ide-2           41945778   114350607  55835  293


No.  Dr Tag FileSystem     Volume      Act StartPos   Sectors    MBytes FreeMB
2:1  E: Pri HPFS/NTFS      apple-win7      63         21944727   10715  92
2:2  F: Pri HPFS/NTFS      my xp       Yes 21944790   43873515   21422  59
2:3  G: Log HPFS/NTFS      SOFT            65818368   205599807  100390 5
2:4  H: Log HPFS/NTFS      media           271418238  205599807  100390 5
2:5  I: Log HPFS/NTFS      backup          477018108  143813817  70221  3
想做个这样的程序。见图

基本完工。只是那个使用了分区的隐藏功能后,无法直观的显示出来。所以计划用全部分区都列表的方式显示在表格。如图

这样就能很好的显示出来全部分区了,包括已经隐藏的分区。也就可以点击所选分区使之显示。
只是最上方的代码的正则表达式,不会写。请大家帮助我。谢谢。
最上面的文本是dsptw生成的。
命令用的是
dsptw 1 /find:all /GhostStyle >>p.txt
dsptw 2 /find:all /GhostStyle >>p.txt
高手出招吧。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-6-6 08:58:16 | 显示全部楼层
论坛已有的dsptw的例子
http://www.autoitx.com/forum.php ... amp;highlight=dsptw
只是他的命令是
dsptw /a /pdr /y      生成的。
对应的正则表达式为  Local $array = StringRegExp($str, '([^\t\r]*)[\t|\r]', 3)

我试验下,用上面的正则表达式,不能达到我的要求。所以发帖求教。
发表于 2010-6-6 10:27:07 | 显示全部楼层
从什么内容中 取出什么内容???
 楼主| 发表于 2010-6-6 10:33:29 | 显示全部楼层
回复 3# 水木子

从最上面的文本,取出

    No.  Dr Tag FileSystem     Volume      Act StartPos   Sectors    MBytes FreeMB


这些内容到
GUICtrlCreateListView
 楼主| 发表于 2010-6-6 10:35:25 | 显示全部楼层

就是提起文本到下面程序的列表中

本帖最后由 23070205 于 2010-6-6 10:39 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ComboConstants.au3>

$Form1 = GUICreate("Eisa 配置", 725, 274, 269, 124);, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$RadioDSPTW = GUICtrlCreateRadio("DSPTW检测模式", 176, 14, 97, 17)
$RadioOMNIFS32 = GUICtrlCreateRadio("OMNIFS32检测模式", 343, 14, 113, 17)
;$Form1_1_2 = GUICreate("Eisa 配置", 725, 174, 269, 124)                                                                                                            8, 68, 600, 113
;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$lvpartitionInfo = GUICtrlCreateListView("硬盘|分区|盘符|序列|分区格式|分区类别|卷标|激活|起始扇区|扇区总数|全部空间(MBs)|剩余空间", 8, 40, 710, 150, $LVS_ICON);25, 180, 345, 113,左侧, 顶部 [, 宽度 [, 高度
;f()
_GUICtrlListView_SetExtendedListViewStyle($lvpartitionInfo, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 0, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 1, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 2, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 3, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 4, 78)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 5, 78)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 6, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 7, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 8, 70)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 9, 70)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 10, 100)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 11, 70)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label14 = GUICtrlCreateLabel("所选分区", 16, 200, 48, 15)
$Inputselectfenqu = GUICtrlCreateInput("", 72, 200, 65, 19,$ES_READONLY)
$Label15 = GUICtrlCreateLabel("修改卷标", 163, 200, 48, 15)
$Inputjuanbiao = GUICtrlCreateInput("", 230, 200, 65, 19)
$Label16 = GUICtrlCreateLabel("修改ID", 315, 200, 38, 15)
$InputxiugaiId = GUICtrlCreateInput("", 366, 200, 65, 19)
$Buttonxiugai = GUICtrlCreateButton("修改", 624, 200, 57, 25)
$Buttonxian= GUICtrlCreateButton("显隐分区", 112, 236, 81, 25)
$Buttonyin = GUICtrlCreateButton("隐藏分区", 247, 236, 81, 25)
$Buttonquit = GUICtrlCreateButton("退出", 382, 236, 81, 25)
$Buttonhelp= GUICtrlCreateButton("帮助", 517, 236, 81, 25)
$Label17 = GUICtrlCreateLabel("修改格式", 449, 200, 48, 15)
$Inputxiugaigeshi = GUICtrlCreateInput("", 508, 200, 65, 19)
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE,$Buttonquit
                        Exit
        EndSwitch
        WEnd
发表于 2010-6-6 10:41:45 | 显示全部楼层
本帖最后由 水木子 于 2010-6-6 10:43 编辑

是以整行的形式取出来 还是单个?

如果是取整行,直接 'No.+'  就可以得到。
 楼主| 发表于 2010-6-6 10:57:54 | 显示全部楼层
不是整行取,要匹配。打开这个效果即可。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-6-6 12:31:49 | 显示全部楼层
做成了这样,不过貌似填写的内容并不准确。
#include <GuiListView.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Eisa 配置", 725, 274, 269, 124);, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$RadioDSPTW = GUICtrlCreateRadio("DSPTW检测模式", 176, 14, 97, 17)
$RadioOMNIFS32 = GUICtrlCreateRadio("OMNIFS32检测模式", 343, 14, 113, 17)
$lvpartitionInfo = GUICtrlCreateListView("硬盘|分区|盘符|序列|分区格式|分区类别|卷标|激活|起始扇区|扇区总数|全部空间(MBs)|剩余空间", 8, 40, 710, 150, $LVS_ICON)
_GUICtrlListView_SetExtendedListViewStyle($lvpartitionInfo, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 0, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 1, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 2, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 3, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 4, 78)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 5, 78)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 6, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 7, 39)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 8, 70)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 9, 70)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 10, 100)
_GUICtrlListView_SetColumnWidth($lvpartitionInfo, 11, 70)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label14 = GUICtrlCreateLabel("所选分区", 16, 200, 48, 15)
$Inputselectfenqu = GUICtrlCreateInput("", 72, 200, 65, 19, $ES_READONLY)
$Label15 = GUICtrlCreateLabel("修改卷标", 163, 200, 48, 15)
$Inputjuanbiao = GUICtrlCreateInput("", 230, 200, 65, 19)
$Label16 = GUICtrlCreateLabel("修改ID", 315, 200, 38, 15)
$InputxiugaiId = GUICtrlCreateInput("", 366, 200, 65, 19)
$Buttonxiugai = GUICtrlCreateButton("修改", 624, 200, 57, 25)
$Buttonxian = GUICtrlCreateButton("显隐分区", 112, 236, 81, 25)
$Buttonyin = GUICtrlCreateButton("隐藏分区", 247, 236, 81, 25)
$Buttonquit = GUICtrlCreateButton("退出", 382, 236, 81, 25)
$Buttonhelp = GUICtrlCreateButton("帮助", 517, 236, 81, 25)
$Label17 = GUICtrlCreateLabel("修改格式", 449, 200, 48, 15)
$Inputxiugaigeshi = GUICtrlCreateInput("", 508, 200, 65, 19)

$aReg = StringRegExp(FileRead('Text.txt'), '.+', 3)
For $i = 0 To UBound($aReg) - 1
        $sReg = StringRegExpReplace(StringRegExpReplace($aReg[$i], ' ', '|'), '\|+', '|')
        GUICtrlCreateListViewItem($sReg, $lvpartitionInfo)
Next

GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3, $Buttonquit
                        Exit
        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
23070205 + 10 感谢水木子老兄,很热心的人。谢谢。

查看全部评分

 楼主| 发表于 2010-6-6 13:09:18 | 显示全部楼层
回复 8# 水木子


    谢谢。要是能准确显示的话,就太好了。我考虑不能准确的原因是因为有些地方是有空格的,老哥可以看看act的那列,问题比较突出些。
发表于 2010-6-6 13:28:27 | 显示全部楼层
好像不难吧
发表于 2010-6-6 13:29:41 | 显示全部楼层
回复 10# afan

向前辈学习!还望前辈赐教。
发表于 2010-6-6 13:55:55 | 显示全部楼层
本帖最后由 afan 于 2010-6-6 14:08 编辑

拿我以前的例子改了下
;
#include <GuiListView.au3>

FileInstall('dsptw.exe', @TempDir & '\')
GUICreate("测试", 560, 200)
$ListView1 = GUICtrlCreateListView('No.|Dr|Tag|FileSystem|Volume|Act|StartPos|Sectors|MBytes|FreeMB', 5, 5, 550, 150)
$BtSx = GUICtrlCreateButton('刷新/载入', 200, 165, 90, 25)
$BtExit = GUICtrlCreateButton('退出', 300, 165, 90, 25)
GUISetState()
_ld()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3, $BtExit
                        FileDelete(@TempDir & '\dsptw.exe')
                        FileDelete(@TempDir & '\diskinfo.txt')
                        Exit
                Case $BtSx
                        _ld()
        EndSwitch
WEnd

Func _ld()
        _GUICtrlListView_DeleteAllItems($ListView1)
        RunWait(@ComSpec & ' /c ' & @TempDir & '\dsptw 1 /find:all /GhostStyle > diskinfo.txt', @TempDir, 0)
        RunWait(@ComSpec & ' /c ' & @TempDir & '\dsptw 2 /find:all /GhostStyle >> diskinfo.txt', @TempDir, 0)
        Local $str = FileRead(@TempDir & '\diskinfo.txt'), $i, $dt
        Local $array = StringRegExp($str, '(\d\:\d+)\h+([C-Z]\:)\h+(.+?)\h+(.+?)\h+(.+?)\h+(Yes|\h+?)\h+(\d+)\h+(\d+)\h+(\d+)\h+(\d+)', 3)
        If @error Then Return MsgBox(48, 0, '错误')
        For $i = 0 To UBound($array) - 10 Step 10
                $dt = $array[$i] & '|' & $array[$i + 1] & '|' & $array[$i + 2] & '|' & $array[$i + 3] & '|' & $array[$i + 4] & '|' & $array[$i + 5] & '|' & $array[$i + 6] & '|' & $array[$i + 7] & '|' & $array[$i + 8] & '|' & $array[$i + 9]
                GUICtrlCreateListViewItem($dt, $ListView1)
        Next
EndFunc   ;==>_ld

评分

参与人数 1金钱 +30 收起 理由
水木子 + 30 学习了,不简单。

查看全部评分

发表于 2010-6-6 14:14:14 | 显示全部楼层
本帖最后由 afan 于 2010-6-6 14:16 编辑

以上重新修改了下,修正对于Volume含有空格的同样能正确显示,如LZ 1# 范本“text.txt”中的“my xp”
以下为LZ提供的范本例子
#include <GuiListView.au3>

GUICreate("测试", 560, 200)
$ListView1 = GUICtrlCreateListView('No.|Dr|Tag|FileSystem|Volume|Act|StartPos|Sectors|MBytes|FreeMB', 5, 5, 550, 150)
GUISetState()
_ld()

While 1
        If GUIGetMsg() = -3 Then Exit
WEnd

Func _ld()
        _GUICtrlListView_DeleteAllItems($ListView1)
        Local $str = FileRead('text.txt'), $i, $dt
        Local $array = StringRegExp($str, '(\d\:\d+)\h+([C-Z]\:)\h+(.+?)\h+(.+?)\h+(.+?)\h+(Yes|\h+?)\h+(\d+)\h+(\d+)\h+(\d+)\h+(\d+)', 3)
        If @error Then Return MsgBox(48, 0, '错误')
        For $i = 0 To UBound($array) - 10 Step 10
                $dt = $array[$i] & '|' & $array[$i + 1] & '|' & $array[$i + 2] & '|' & $array[$i + 3] & '|' & $array[$i + 4] & '|' & $array[$i + 5] & '|' & $array[$i + 6] & '|' & $array[$i + 7] & '|' & $array[$i + 8] & '|' & $array[$i + 9]
                GUICtrlCreateListViewItem($dt, $ListView1)
        Next
EndFunc   ;==>_ld

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 2金钱 +40 收起 理由
23070205 + 10 感谢afan超版。
水木子 + 30 厉害!

查看全部评分

 楼主| 发表于 2010-6-6 15:46:01 | 显示全部楼层
刚才停电了,一上来就发现问题解决了。感谢afan和水木子两位大哥出手。谢谢。
发表于 2010-6-6 15:46:50 | 显示全部楼层
呵呵
恰到好处的正则应用真是令人赏心悦目!
学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 04:50 , Processed in 0.095975 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表