Fileopen problem

  • gibt es ein befehl um eine textdatei zu erstellen??

    6 Mal editiert, zuletzt von crocojunk (15. April 2010 um 01:00)

  • spontanes beispiel:

    [autoit]

    #Include <File.au3>
    _FileCreate(@TempDir&"\gibtsnicht.txt")
    FileOpen(@TempDir&"\gibtsnicht.txt", 2)
    FileWriteLine(@TempDir&"\gibtsnicht.txt", "test123")
    FileClose(@TempDir&"\gibtsnicht.txt")
    msgbox(0,"",FileReadLine ( @TempDir&"\gibtsnicht.txt", 1))

    [/autoit]
  • _FileCreate brauchst du nicht mal um eine Datei zu erstellen. Da reicht FileOpen oder FileWrite.

  • funzt super kann ich es dann auch beliebig bennen muss ich dann einfach anstatt Text.txt das text weglassen?

    oder wie geht das?

    EDIT// Noch ne frage wenn ich die datei öffnen will wie geht das ??

    ich hab immer

    [autoit]

    $öffnen = Fileopendiaolog ("Öffnen","C\Users\","(*txt)")
    Fileopen ($öffnen)

    [/autoit]

    2 Mal editiert, zuletzt von crocojunk (10. April 2010 um 01:46)

  • Zitat

    muss ich dann einfach anstatt Text.txt das text weglassen?


    ....
    FileOpen öffnet normalerweise die Datei die du als Parameter angibst.
    Und wenn die Datei nicht existiert und FileOpen mit einem Schreibmodus als zweiten Parameter ausgeführt wird, wird die Datei einfach erstellt.
    Also gib statt Test.txt einfach die Datei an die du erstellt haben willst z.B. LießMalDieHilfe.txt oder HörEinfachMalZu.sonstnochwas.

    Zitat

    Fileopendiaolog


    :rofl:
    Das heißt FileOpenDialog! Und Variablen mit Umlauten gibt's auch nicht. :cursing:

  • ich meine wenn ich z.B. eine txt datei erstellt hab und möchte diese öffnen was muss für ein befehl schreiben??

    denn mit FileOpenDialog seh ich die datein kann sie aber nicht öffnen.

  • also ich hab es jetzt hingekriegt es funktioniert mit

    [autoit]

    $file = FileOpenDialog ("Datei auswählen", "C\Users\" , "Text Datein(*.txt)")
    GUICtrlSetData ($Edit1, FileRead ($file))

    [/autoit]

    kann ich dann auch eigene datei formate erstellen??

  • ich hab jetzt nur noch ein problem ich kann es immer noch nicht beliebig bennen

    [autoit]

    $file = FileSaveDialog ("Datei Speichern", "", "(*croco)",)
    $save = FileWrite(@DesktopDir&"\.croco",GUICtrlRead ($Edit1))

    [/autoit]

    und ich möchte auch das man auswählen kann ob txt datei oder .croco geht das??

    danke

  • [autoit]

    $file = FileSaveDialog ("Datei Speichern", "", "(*croco)",)

    [/autoit]


    1. zwischen * und croco fehlt ein Punkt.
    2. Da ist ein Komma zu viel (Vor der letzen schließenden Klammer)

    [autoit]

    $save = FileWrite(@DesktopDir&"\.croco",GUICtrlRead ($Edit1))

    [/autoit]


    3. Du speicherst einfach eine Datei Namens ".croco" auf deinen Desktop, ohne Bezug auf den FileSaveDialog zu nehmen.
    Warum?

    Für mehrere Dateitypen:
    Guck dir die Hilfe zu FileSaveDialog nochmal an.
    Und wenn du es dann nicht hast, dann guck nochmal rein.
    Und dann guckst du nochmal!

    Es steht nämlich drin. Und nichtmal versteckt.

    Außerdem möchte ich bitte, dass du über 1., 2. und 3. aus meinem Post nachdenkst, und versuchst das zu beheben.
    Learning by Doing und so

  • so ich hab mir alles nochmal angeschaut und du hattest recht ich habs wohl übersehen SEuBo.

    ich hab alles hingekriegt aber er will nicht die datei dahin schreiben wo ich es mit Filesavedialog ausgewählt hab.

    ich hab folgendes stehen

    [autoit]

    $file = FileSaveDialog ("Datei Speichern", "", "(*.croco)|Texdatein (*.ini ;*.txt)")
    FileWrite ($file&"\.croco\.ini;.txt", GUICtrlRead ($Edit1))

    [/autoit]
  • Zitat

    FileWrite ($file&"\.croco\.ini;.txt"


    Was sollen auch die Dateiformate mit Backslash getrennt hinten dran? Meinst du AutoIt ist so nett und sucht sich eine Endung für dich aus?
    Mach es doch einfach so:

    [autoit]

    FileWrite($file, "Text der in die Datei geschrieben wird")

    [/autoit]
  • er schreibt die datei jetzt endlich nur nicht als text datei

    EDIT\\ er erstellt die datei auch nur nicht als ausgewählte dateiformat.

    Einmal editiert, zuletzt von crocojunk (10. April 2010 um 15:10)

  • Dafür gibts eine FileSaveDialog UDF, die diesen "Bug" behebt

    Spoiler anzeigen
    [autoit]

    $hWnd = WinGetHandle("")
    $sFilter = "Text File (*.txt)|*.txt|AutoIt v3 Script (*.au3)|*.au3|All (*.*)|*.*"

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

    $Ret = _FileSaveDialog("Save as", "C:\", $sFilter, 18, "New Script", 2, $hWnd)

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

    If Not @error Then MsgBox(64, "Results", StringFormat("Saved as: %s\n\nSelected Filter Index: %d", $Ret, @extended))

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

    Func _FileSaveDialog($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefFile = '', $iDefFilter = 1, $hWnd = 0)
    Local $iFileLen = 65536 ; Max chars in returned string

    ; API flags prepare
    Local $iFlag = BitOR(BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 16), 3))

    ; Filter string to array convertion
    If Not StringInStr($sFilter, '|') Then $sFilter &= '|*.*'
    $sFilter = StringRegExpReplace($sFilter, '|+', '|')

    Local $asFLines = StringSplit($sFilter, '|')
    Local $i, $suFilter = ''

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

    For $i = 1 To $asFLines[0] Step 2
    If $i < $asFLines[0] Then _
    $suFilter &= 'byte[' & StringLen($asFLines[$i]) + 1 & '];char[' & StringLen($asFLines[$i + 1]) + 1 & '];'
    Next

    ; Create API structures
    Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
    ';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')
    Local $usTitle = DllStructCreate('char[' & StringLen($sTitle) + 1 & ']')
    Local $usInitDir = DllStructCreate('char[' & StringLen($sInitDir) + 1 & ']')
    Local $usFilter = DllStructCreate($suFilter & 'byte')
    Local $usFile = DllStructCreate('char[' & $iFileLen & ']')
    Local $usExtn = DllStructCreate('char[1]')

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

    For $i = 1 To $asFLines[0]
    DllStructSetData($usFilter, $i, $asFLines[$i])
    Next

    ; Set Data of API structures
    DllStructSetData($usTitle, 1, $sTitle)
    DllStructSetData($usInitDir, 1, $sInitDir)
    DllStructSetData($usFile, 1, $sDefFile)
    DllStructSetData($usExtn, 1, "")
    DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
    DllStructSetData($uOFN, 2, $hWnd)
    DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
    DllStructSetData($uOFN, 7, $iDefFilter)
    DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
    DllStructSetData($uOFN, 9, $iFileLen)
    DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
    DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
    DllStructSetData($uOFN, 14, $iFlag)
    DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
    DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))

    ;Set Timer to check FileName Input for file extension
    Local $hCallBack = DllCallbackRegister("_Check_FSD_Input", "none", "hwnd;int;int;dword")
    Local $ahTimer = DllCall("user32.dll", "int", "SetTimer", "hwnd", 0, _
    "int", TimerInit(), "int", 100, "ptr", DllCallbackGetPtr($hCallBack))

    ; Call API function
    Local $aRet = DllCall('comdlg32.dll', 'int', 'GetSaveFileName', 'ptr', DllStructGetPtr($uOFN))

    ;Free CallBack and kill the timer
    DllCallBackFree($hCallBack)
    DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $ahTimer)

    If Not IsArray($aRet) Or Not $aRet[0] Then Return SetError(1, 0, "")

    ;Return Results
    Local $sRet = StringStripWS(DllStructGetData($usFile, 1), 3)
    Return SetExtended(DllStructGetData($uOFN, 7), $sRet) ;@extended is the 1-based index of selected filter
    EndFunc ;==>_FileSaveDialog

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

    Func _Check_FSD_Input($hWndGUI, $MsgID, $WParam, $LParam)
    Local $sSaveAs_hWnd = _WinGetHandleEx(@AutoItPID, "#32770", "", "FolderView")

    If ControlGetFocus($sSaveAs_hWnd) = "Edit1" Then Return

    Local $sEdit_Data = ControlGetText($sSaveAs_hWnd, "", "Edit1")
    Local $sFilter_Ext = ControlCommand($sSaveAs_hWnd, "", "ComboBox3", "GetCurrentSelection")
    $sFilter_Ext = StringRegExpReplace($sFilter_Ext, ".*\(\*(.*?)\)$", "\1")

    If $sFilter_Ext = ".*" Then
    $sFilter_Ext = ""
    ElseIf Not StringInStr($sFilter_Ext, ".") Then
    Return
    EndIf

    Local $sEdit_Ext = StringRegExpReplace($sEdit_Data, "^.*\.", ".")

    If $sEdit_Ext <> $sFilter_Ext And ($sEdit_Ext <> $sEdit_Data Or $sFilter_Ext <> "") Then
    $sEdit_Data = StringRegExpReplace($sEdit_Data, "\.[^.]*$", "")
    ControlSetText($sSaveAs_hWnd, "", "Edit1", $sEdit_Data & $sFilter_Ext)
    EndIf
    EndFunc ;==>_Check_FSD_Input

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

    Func _WinGetHandleEx($iPID, $sClassNN="", $sPartTitle="", $sText="", $iVisibleOnly=1)
    If IsString($iPID) Then $iPID = ProcessExists($iPID)

    Local $aWList = WinList("[CLASS:" & $sClassNN & ";REGEXPTITLE:(?i).*" & $sPartTitle & ".*]", $sText)
    If @error Then Return SetError(1, 0, "")

    For $i = 1 To $aWList[0][0]
    If WinGetProcess($aWList[$i][1]) = $iPID And (Not $iVisibleOnly Or _
    ($iVisibleOnly And BitAND(WinGetState($aWList[$i][1]), 2))) Then Return $aWList[$i][1]
    Next

    Return SetError(2, 0, "")
    EndFunc ;==>_WinGetHandleEx

    [/autoit]