Phatangeaben Program soll wie Explorer zu Datei fuehren

  • Sowas suche ich. Ich habe keine ahnung wie ich sowas realisieren soll. Viel Programe fragen nach einer Datei x. Dan kan man sich yu der durchhangeln (Durchsuchen) und ok druecken. Sowas moechte ich auch.

    • Offizieller Beitrag

    Also einen einfachen Datei-Explorer.
    Hatte ich vor Urzeiten mal gemacht. :D
    Inklusive Doppelklick zum Ausführen der Dateien und Kontextmenü (Ausführen, Kopieren, Einfügen, Umbenennen, Löschen).

    Spoiler anzeigen
    [autoit]

    #include<GUIConstantsEx.au3>
    #include<ListBoxConstants.au3>
    #include<WindowsConstants.au3>
    #include <GuiListBox.au3>
    #include <File.au3>

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

    Global $aFile, $aFolder, $aPath[1] = [@HomeDrive & '\'], $currPath, $sUp = '[ EBENE HÖHER ]'
    Global $Safed = '[SHOC]' ; mit diesen Attributen gesperrt für: Ausführen, Umbenennen, Löschen

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

    $GUI = GUICreate("Simple Explorer",400,300)
    $label = GUICtrlCreateLabel('', 5, 5, 390, 53)
    $List = GUICtrlCreateList( '', 2, 65, 396, 230, BitOR($WS_HSCROLL, $WS_VSCROLL, $WS_BORDER))
    $hList = GUICtrlGetHandle($List)
    $menu = GUICtrlCreateContextMenu($List)
    $itemRun = GUICtrlCreateMenuItem('Ausführen', $menu)
    $itemShape = GUICtrlCreateMenuItem('', $menu)
    $itemCopy = GUICtrlCreateMenuItem('Kopieren', $menu)
    $itemPaste = GUICtrlCreateMenuItem('Einfügen', $menu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $itemRen = GUICtrlCreateMenuItem('Umbenennen', $menu)
    $itemShape = GUICtrlCreateMenuItem('', $menu)
    $itemDel = GUICtrlCreateMenuItem('Löschen', $menu)
    GUISetState(@SW_SHOW)

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

    GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

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

    _WriteList($aPath[0])

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $itemRun
    _RunFile()
    Case $itemCopy
    _CopyFile()
    Case $itemPaste
    _PasteFile()
    Case $itemRen
    _RenFile()
    Case $itemDel
    _DelFile()
    EndSwitch
    Wend

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

    Func _WriteList($PATH)
    _GUICtrlListBox_ResetContent($hList) ; alte Inhalte löschen
    $aFolder = _FileListToArray($PATH, '*', 2)
    $aFile = _FileListToArray($PATH, '*', 1)
    If UBound($aPath) > 1 Then _GUICtrlListBox_AddString($hList, $sUp)
    If IsArray($aFolder) Then
    _GUICtrlListBox_AddString($hList, '--------------- ORDNER ---------------')
    For $i = 1 To UBound($aFolder) -1
    _GUICtrlListBox_AddString($hList, $aFolder[$i])
    Next
    EndIf
    If IsArray($aFile) Then
    _GUICtrlListBox_AddString($hList, '--------------- DATEIEN ---------------')
    For $i = 1 To UBound($aFile) -1
    _GUICtrlListBox_AddString($hList, $aFile[$i])
    Next
    EndIf
    GUICtrlSetData($label, $PATH)
    EndFunc

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

    Func _ListDblClick()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    Local $tmpPath = ''
    If $str = $sUp Then
    ReDim $aPath[UBound($aPath)-1]
    $currPath = $aPath[UBound($aPath)-1]
    _WriteList($currPath)
    Else
    $currPath = $aPath[UBound($aPath)-1] & $str & '\' ; neuer Pfad = letzter Pfad + geklickter Pfad
    If Not StringRegExp(FileGetAttrib($currPath), 'D') Then ; ist es kein Ordner ?
    _RunFile()
    Else
    ReDim $aPath[UBound($aPath)+1]
    $aPath[UBound($aPath)-1] = $currPath ; neuen Pfad hinzufügen
    _WriteList($currPath)
    EndIf
    EndIf
    EndFunc

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

    Func _RunFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    ShellExecuteWait($aPath[UBound($aPath)-1] & $str)
    EndFunc

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

    Func _CopyFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, 'D') Then Return MsgBox(0, 'Achtung', $str & ' ist keine Datei')
    ClipPut($aPath[UBound($aPath)-1] & $str)
    GUICtrlSetState($itemPaste, $GUI_ENABLE)
    EndFunc

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

    Func _PasteFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If Not StringRegExp($attrib, 'D') Then Return MsgBox(0, 'Achtung', $str & ' - ist kein Ordner')
    Local $tmp = ClipGet(), $pos = StringInStr($tmp, '\', -1)
    Local $file = StringRight($tmp, StringLen($tmp)-$pos)
    If FileExists($aPath[UBound($aPath)-1] & $str & '\' & $file) Then $file = 'Kopie von ' & $file
    FileCopy($tmp, $aPath[UBound($aPath)-1] & $str & '\' & $file)
    _WriteList($aPath[UBound($aPath)-1])
    GUICtrlSetState($itemPaste, $GUI_DISABLE)
    EndFunc

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

    Func _RenFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    Local $tmp = InputBox('Umbenennen', 'Neuer Name:' & @LF & @LF & $aPath[UBound($aPath)-1], $str)
    If $tmp <> '' Then FileMove($aPath[UBound($aPath)-1] & $str, $aPath[UBound($aPath)-1] & $tmp)
    _WriteList($aPath[UBound($aPath)-1])
    EndFunc

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

    Func _DelFile()
    Local $str = _GUICtrlListBox_GetText($hList, _GUICtrlListBox_GetCurSel($hList))
    If $str = '' Then Return
    Local $attrib = FileGetAttrib($aPath[UBound($aPath)-1] & $str)
    If StringRegExp($attrib, $Safed) Then Return MsgBox(0, 'Geschützt!', $str & ' - Attribut: ' & $attrib)
    FileDelete($aPath[UBound($aPath)-1] & $str)
    _WriteList($aPath[UBound($aPath)-1])
    EndFunc

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($hList) Then $hWndListBox = GUICtrlGetHandle($hList)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
    Case $hList, $hWndListBox
    Switch $iCode
    Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
    _ListDblClick()
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]

    Oder meinst du evtl. einfach nur: FileOpenDialog() ?

  • Der kleine unscheinbare Tipp @FileOpenDialog@ hat mich zum Ziel gefuert. Danke. Juhu >< Freu


    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>

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

    GUICreate("Phat", 500, 400)

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

    GUICtrlCreateGroup("Datei öffnen", 10, 10, 480, 60)
    $button = GUICtrlCreateButton("Durchsuchen...", 370, 30, 100, 25)
    $input = GUICtrlCreateInput("", 30, 30, 320, 25)
    GUISetState()

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

    While 1
    $msg = GUIGetMsg()

    Switch $msg

    Case $GUI_EVENT_CLOSE
    Exit
    Case $button
    $re = FileOpenDialog("Datei öffnen", @DesktopDir, "Alle Dateien (*.*)")
    If @error Then
    MsgBox(16, Default, "FOD", 5)
    EndIf
    GUICtrlSetData($input, $re)
    EndSwitch

    WEnd

    [/autoit]
  • Ich wei- jetyt nicht wo das noch muckt. Case $Button1S Funzt gut. Doch warum wird jetzt die SkriptPathangaben.txt in den Ordner gespeicher wo der Phad liegt? Die Datei existiert in dem Ordner wo die .au3 ist. Also mein Naviigations Datenbank programm xD.


    Spoiler anzeigen
    [autoit]


    Case $Button1S
    $re = FileOpenDialog("Datei öffnen", @DesktopDir, "Alle Dateien (*.*)")
    If @error Then
    MsgBox(16, Default, "FOD", 5)
    EndIf
    GUICtrlSetData($Input1S, $re)
    Case $Button2S
    $Path = GuiCtrlRead($Input1S)
    If FileExists(@ScriptDir & '\SkriptPathangaben.txt') Then
    $file = FileOpen ( "SkriptPathangaben.txt", 1 )
    If $file = -1 Then
    MsgBox(0, "Error", "Kann Datei nicht Öffnen!")
    Exit
    EndIf
    FileWrite($file, @CRLF)
    FileWrite($file, $Path )
    FileClose($file)
    Else
    MsgBox(4096,"Warnung" , "SkriptPathangaben.txt does NOT exists")
    EndIf
    msgbox(0, "INFO", "Phad gespeichert")

    [/autoit]


    PS> Hab den Fehler gefunden $file = FileOpen (@ScriptDir & "\SkriptPathangaben.txt", 1 ) so mus es sein.

    2 Mal editiert, zuletzt von Skar (1. Oktober 2009 um 10:37)