Filopen Dialog Textfile filtern

  • Moin,

    habt ihr eine Idee, wie man beim Fileopen Dialog,

    $Fileopen= FileOpenDialog($message, @HomeDrive, "Textdatei (*.txt)", 1 + 4 )

    eine Textdatei beginnend mit "9935_txt" abfiltern kann.

    Gruß

    wuff

    Einmal editiert, zuletzt von wuff100 (23. Januar 2011 um 19:39)

    • Offizieller Beitrag

    Ich habe Dir mal ein Auswahl-Dialog erstellt, bei dem man ein RegExp-Pattern angeben kann.
    In dem Beispiel werden alle Dateien angezeigt, die nicht diesem Muster "9935_x.txt" (wobei das x für beliebige Zeichen steht) entsprechen:

    Spoiler anzeigen
    [autoit]


    $sFiles = _FileOpenDialog('Datei(en) auswählen', @ScriptDir, '^9935_.*\.txt', 0)
    If Not @error Then MsgBox(0, 'Datei(en):', $sFiles)

    [/autoit] [autoit][/autoit] [autoit]

    Func _FileOpenDialog($sTitle, $sInitDir, $sPattern = '.*', $iOptions = 0, $hWnd = 0)
    Local $iOldOpt, $hSearch, $hGui, $hFileList, $hFile, $sDate, $iSize, $hOk, $hCancel, $aMsg
    If Not FileExists($sInitDir) Then Return SetError(1, 0, '')
    If StringRight($sInitDir, 1) <> '\' Then $sInitDir &= '\'
    $hSearch = FileFindFirstFile($sInitDir & '*.*')
    If $hSearch = -1 Then Return SetError(2, 0, '')
    $iOldOpt = Opt('GUIOnEventMode', 0)
    $hGui = GUICreate($sTitle, 600, 400, -1, -1, BitOR(-2134245376, 262144), Default, $hWnd) ; -2134245376 = $GUI_SS_DEFAULT_GUI, 262144 = $WS_SIZEBOX
    $hFileList = GUICtrlCreateListView('Name|Änderungsdatum|Größe', 10, 10, 580, 350, BitOR(8, BitXOR(BitAND($iOptions, 4), 4))) ; 8 = $LVS_SHOWSELALWAYS, 4 = $LVS_SINGLESEL
    While True
    $hFile = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    If @extended Or StringRegExp($hFile, $sPattern) Then ContinueLoop
    $sDate = StringRegExpReplace(FileGetTime($sInitDir & $hFile, 0, 1), '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})', '$3.$2.$1 $4:$5:$6')
    $iSize = FileGetSize($sInitDir & $hFile)
    GUICtrlCreateListViewItem($hFile & '|' & $sDate & '|' & $iSize, $hFileList)
    WEnd
    FileClose($hSearch)
    GUICtrlSendMsg($hFileList, 4126, 0, -1) ; 4126 = $LVM_SETCOLUMNWIDTH, -1 = $LVSCW_AUTOSIZE
    $hOk = GUICtrlCreateButton('Ok', 430, 370, 65, 22)
    GUICtrlSetResizing(-1, 1 + 64)
    $hCancel = GUICtrlCreateButton('Abbrechen', 500, 370, 90, 22)
    GUICtrlSetResizing(-1, 1 + 64)
    GUISetState()
    While True
    $aMsg = GUIGetMsg(True)
    Switch $aMsg[1]
    Case $hGui
    Switch $aMsg[0]
    Case $hCancel, -3 ; -3 = $GUI_EVENT_CLOSE
    GUIDelete($hGui)
    Opt('GUIOnEventMode', $iOldOpt)
    Return SetError(3, 0, '')
    Case $hOk
    $sSelect = ControlListView($hGui, '', $hFileList, 'GetSelected', 1)
    If $sSelect <> '' Then
    $aItems = StringSplit($sSelect, '|')
    $sSelect = ''
    For $i = 1 To $aItems[0]
    $sSelect &= ControlListView($hGui, '', $hFileList, 'GetText', $aItems[$i]) & '|'
    Next
    $sSelect = StringTrimRight($sSelect, 1)
    EndIf
    GUIDelete($hGui)
    Opt('GUIOnEventMode', $iOldOpt)
    Return $sSelect
    EndSwitch
    EndSwitch
    WEnd
    EndFunc

    [/autoit]