求正则表达式,dsptw生成的文本到listview【已解决】
本帖最后由 23070205 于 2010-6-6 16:41 编辑No.Dr Tag FileSystem Volume Act StartPos Sectors MBytes FreeMB
1:1C: Log HPFS/NTFS IDE-1 16128 41929587 204731
1:2D: Log HPFS/NTFS ide-2 41945778 11435060755835293
No.Dr Tag FileSystem Volume Act StartPos Sectors MBytes FreeMB
2:1E: Pri HPFS/NTFS apple-win7 63 21944727 1071592
2:2F: Pri HPFS/NTFS my xp Yes 21944790 43873515 2142259
2:3G: Log HPFS/NTFS SOFT 65818368 205599807100390 5
2:4H: Log HPFS/NTFS media 271418238205599807100390 5
2:5I: Log HPFS/NTFS backup 477018108143813817702213
想做个这样的程序。见图
基本完工。只是那个使用了分区的隐藏功能后,无法直观的显示出来。所以计划用全部分区都列表的方式显示在表格。如图
这样就能很好的显示出来全部分区了,包括已经隐藏的分区。也就可以点击所选分区使之显示。
只是最上方的代码的正则表达式,不会写。请大家帮助我。谢谢。
最上面的文本是dsptw生成的。
命令用的是
dsptw 1 /find:all /GhostStyle >>p.txt
dsptw 2 /find:all /GhostStyle >>p.txt
高手出招吧。 论坛已有的dsptw的例子
http://www.autoitx.com/forum.php?mod=viewthread&tid=15343&highlight=dsptw
只是他的命令是
dsptw /a /pdr /y 生成的。
对应的正则表达式为Local $array = StringRegExp($str, '([^\t\r]*)[\t|\r]', 3)
我试验下,用上面的正则表达式,不能达到我的要求。所以发帖求教。 从什么内容中 取出什么内容??? 回复 3# 水木子
从最上面的文本,取出
No.Dr Tag FileSystem Volume Act StartPos Sectors MBytes FreeMB
这些内容到
GUICtrlCreateListView
就是提起文本到下面程序的列表中
本帖最后由 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:43 编辑
是以整行的形式取出来 还是单个?
如果是取整行,直接 'No.+'就可以得到。 不是整行取,要匹配。打开这个效果即可。
做成了这样,不过貌似填写的内容并不准确。#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 回复 8# 水木子
谢谢。要是能准确显示的话,就太好了。我考虑不能准确的原因是因为有些地方是有空格的,老哥可以看看act的那列,问题比较突出些。 好像不难吧 回复 10# afan
向前辈学习!还望前辈赐教。 本帖最后由 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+(\:)\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 本帖最后由 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+(\:)\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 刚才停电了,一上来就发现问题解决了。感谢afan和水木子两位大哥出手。谢谢。 呵呵
恰到好处的正则应用真是令人赏心悦目!
学习了