本帖最后由 夜猫猫 于 2011-8-12 08:47 编辑
另一贴的问题。提来问问。寻求解决。自己搞了两天了,该有的想法都测试了。还是行不通。。。。达不到效果。
我需要的最终配置表INI
========================
[配置]
XX=XX
XX=XX
[网络游戏]
XX=XX\XX\XXXXX
XX=XX\XX\XXX\XXXXX
[单机游戏]
XX=XX\XX\XXXXX
XX=XX\XX\XXX\XXXXX
=============================
INI.选择输出的时候,会写入.但.没有选取的.INI文件里已经有的会被删除,写入新选取的.怎么从相应的字段尾行写入数据?清理相同的?
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\WINDOWS\system32\SHELL32.dll|-23
#AutoIt3Wrapper_Res_Comment=文件搜索 BY 夜MaoMao
#AutoIt3Wrapper_Res_Description=文件搜索
#AutoIt3Wrapper_Res_FileVersion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=1.0.0.0
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#cs ------------------------------------
脚本作者:夜MaoMao
Email:yuko1176@126.com
操作系统版本:Win SP2/ W7
操作系统语言:GB2312
autoit版本:.3.6.1-2
#ce ------------------------------------
;脚本开始
#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <SendMessage.au3>
Local $arr, $num, $str
Local $chen
Global $icon, $CKBOXE_ID[1000], $CT1
Global $Ini=@ScriptDir & "\LOGO.ini"
$Skin_dll = @TempDir & "\Skin.dll"
$Skin_she = @TempDir & "\black.she"
FileInstall("Skin.dll", $Skin_dll)
FileInstall("black.she", $Skin_she)
Skin($Skin_dll, $Skin_she)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("搜索文件", 564, 577, 192, 124)
$Label1 = GUICtrlCreateLabel("搜索路径:", 20, 42, 60, 20)
$Input1 = GUICtrlCreateInput("G:\网络游戏", 75, 37, 115, 20)
$Label2 = GUICtrlCreateLabel("搜索匹配:", 263, 42, 60, 20)
$Input2 = GUICtrlCreateInput("QQSG,Launcher,QQSpeedLauncher,Setup,Login", 318, 37, 133, 20)
$Label2 = GUICtrlCreateLabel("层数:", 470, 42, 60, 20)
$Combo1 = GUICtrlCreateCombo("1", 500, 37, 40, 20)
GUICtrlSetData(-1, "2|3|4|5|6", "1")
$LabelA1 = GUICtrlCreateLabel("总项目计数:", 63, 115, 120, 20)
$Button1 = GUICtrlCreateButton("浏览", 193, 35, 50, 25)
$Button2 = GUICtrlCreateButton("搜索", 232, 95, 97, 33)
$Button3 = GUICtrlCreateButton("(全选)", 132, 542, 60, 25)
$Button4 = GUICtrlCreateButton("(添加)", 332, 537, 60, 25)
$Label3 = GUICtrlCreateLabel("", 30, 70, 300, 20)
$Edit1 = GUICtrlCreateEdit("", 5, 440, 555, 100, $ES_AUTOVSCROLL + $WS_VSCROLL)
GUICtrlSetData($Edit1, FileRead($Ini))
$ListView = GUICtrlCreateListView(' 选择| 主文件夹名 | 文件路径', 5, 140, 555, 290)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($ListView, 0, 61)
_GUICtrlListView_SetColumnWidth($ListView, 1, 100)
_GUICtrlListView_SetColumnWidth($ListView, 2, 355)
$LHand = GUICtrlGetHandle($ListView)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
FileDelete($Skin_dll)
FileDelete($Skin_she)
Case $Button1
$file = FileSelectFolder("选择文件夹.", "")
GUICtrlSetData($Input1, $file)
Case $Button2
_SendMessage($LHand, $LVM_DELETEALLITEMS)
GUICtrlSetData($Label3,"正在搜索中....")
ct1()
$chen = GUICtrlRead($Combo1) + 1
_filelist(GUICtrlRead($Input1))
If _GUICtrlListView_GetItemCount($ListView) = 0 Then
CCT1()
GUICtrlSetData($Label3,"没有找到任何文件,请确认路径/匹配/目录层是否有错!")
ct3()
ElseIf _GUICtrlListView_GetItemCount($ListView) > 0 Then
CCT1()
GUICtrlSetData($LabelA1, "搜索到: " & _GUICtrlListView_GetItemCount($ListView) & " 个文件")
ct2()
GUICtrlSetData($Label3,"搜索完成!")
EndIf
Case $Button3
_GUICtrlListView_SetItemChecked($ListView, -1)
Case $Button4
Local $jg = ""
Dim $a, $b
For $i = 0 To _GUICtrlListView_GetItemCount($ListView)
$M = _GUICtrlListView_GetItemText($ListView, $i, 1)
$N = _GUICtrlListView_GetItemText($ListView, $i, 2)
If _GUICtrlListView_GetItemChecked(GUICtrlGetHandle($ListView), $i) = $GUI_CHECKED Then
$jg &= $M & "=" & $N & @CRLF
EndIf
Next
$sr = StringRegExp($jg, '([^\→]*)\=(.+?)(?:\r\n|$)', 1) ;上面的$M $N 这里无法获取,只好在匹配下拆分出来,
If Not @error Then
For $i = 0 To UBound($sr) - 1
If $sr[$i] > "" Then
$a = $sr[0]
$b = $sr[1]
EndIf
Next
EndIf
$hSouce = IniReadSection($Ini, "网络游戏")
For $i = 1 To $hSouce[0][0]
If StringInStr($hSouce[$i][0], $a) Then ;对比关键字,匹配则跳出
ContinueLoop
Else
IniWriteSection($Ini, "网络游戏", $jg)
EndIf
Next
GUICtrlSetData($Edit1, FileRead($Ini))
MsgBox(32, "", "添加完成 !")
EndSwitch
WEnd
;主程序
Func _filelist($searchdir)
$search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
Local $sPathExclude = GUICtrlRead($Input2) ;搜索使用不排除的数值
If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
While 1
$file = FileFindNextFile($search) ;;;查找下一个文件
If @error Then ;;;如果找不到文件
FileClose($search) ;;;则关闭此句柄
Return ;;;返回
ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
ContinueLoop
ElseIf StringInStr(FileGetAttrib($searchdir & "\" & $file), "D") Then;;如果找到的是一个文件夹,则
$arr = StringRegExp($searchdir & "\" & $file, '\\', 3)
$num = UBound($arr)
If $num < $chen Then
_filelist($searchdir & "\" & $file) ;;递归调用filelist函数,并传参数
EndIf
EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
$a_Arr = StringSplit($searchdir & "\" & $file, "\") ;拆分路径。判断输出文件夹名
If UBound($a_Arr) = 2 Then
$FileNmae = $a_Arr[0]
ElseIf UBound($a_Arr) = 3 Then
$FileNmae = $a_Arr[1]
ElseIf UBound($a_Arr) = 4 Then
$FileNmae = $a_Arr[2]
Else
$FileNmae = $a_Arr[3]
EndIf
If $sPathExclude And StringLen($sPathExclude) > 0 Then $sPathExclude = StringSplit($sPathExclude, ",");读取排除数值
For $i = 1 To UBound($sPathExclude) - 1
$ext = "exe" ;扩展名
If StringRight($searchdir & "\" & $file, StringLen($ext)) = $ext And StringInStr($file, $sPathExclude[$i] & "." & $ext) And StringRight($file, StringLen($sPathExclude[$i] & "." & $ext)) = $file Then ;匹配对象输出并将数值显示在ListView
$CKBOXE_ID[$i] = GUICtrlCreateListViewItem(" |" & $FileNmae & '|' & $searchdir & "\" & $file, $ListView)
GUICtrlSetImage(-1, $searchdir & "\" & $file)
If StringInStr($file, '.EXE') Then $str &= $searchdir & "\" & $file & @CRLF;
EndIf
Next
WEnd
EndFunc
;提示窗口
Func CCT1()
GUIDelete($CT1)
EndFunc
Func ct1()
$CT1 = GUICreate("窗体1", 222, 88, 180, 220, 0x80880000, 0x00000040, $Form1)
$Labe01 = GUICtrlCreateLabel("搜索中!请稍等...", 24, 32, 174, 24)
GUICtrlSetFont(-1, 15, 400, 0, "黑体")
GUICtrlSetColor(-1, 0xAA0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetTrans($CT1, "", 200)
EndFunc ;==>ct1
Func ct2()
$CT2 = GUICreate("窗体1", 222, 88, 180, 220, 0x80880000, 0x00000040, $Form1)
$Labe02 = GUICtrlCreateLabel(" 搜索完成 !", 50, 32, 174, 24)
GUICtrlSetFont($Labe02, 15, 400, 0, "黑体")
GUICtrlSetColor($Labe02, 0xFFAA00)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetTrans($CT2, "", 200)
While 1
Sleep(1000)
GUIDelete($CT2)
ExitLoop
WEnd
EndFunc ;==>ct2
Func ct3()
$CT3 = GUICreate("窗体1", 222, 88, 180, 220, 0x80880000, 0x00000040, $Form1)
$Labe03 = GUICtrlCreateLabel("没有找到任何文件,请确认路径/匹配/目录层是否有错!", 7, 22, 220, 44)
GUICtrlSetFont($Labe03, 12, 400, 0, "黑体")
GUICtrlSetColor($Labe03, 0xFF00AA)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetTrans($CT3, "", 200)
While 1
Sleep(2000)
GUIDelete($CT3)
ExitLoop
WEnd
EndFunc ;==>ct3
;皮肤
Func Skin($Skin_dll, $Skin_she)
$Dll = DllOpen($Skin_dll)
DllCall($Dll, "int", "SkinH_AttachEx", "str", $Skin_she, "str", "mhgd")
DllCall($Dll, "int", "SkinH_SetAero", "int", 1)
EndFunc ;==>Skin
|