Hallo ich brauch mal Eure Hilfe, ich komme nicht weiter.
Ich habe eine Datei "untitled.txt" in der möchte ich den String "version 9" in "version 7" ändern.
Wenn ich die Datei mit notepad++ öffne und es händisch ändere und wieder abspeiche funktioniert es.
In meiner GUI füge ich per Drag and Drop die Datei ein.
Aber mit _ReplaceStringInFile funktioniert es nicht.
Ich denke mir, es liegt an der Datei, weil weiter unten in der Datei stehen so komische Zeichen, siehe Anhang.
Hat jemand eine Idee, wie ich das lösen kann.
Danke im vorraus.
C
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
Global $gaDropFiles[1], $iDropItem = -1
#Region ###
Global $Form1 = GUICreate("", 200, 200, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_ACCEPTFILES, $WS_EX_CONTROLPARENT)) ;$WS_EX_CONTROLPARENT = verschiebt Fenster auch ohne Rahmen
GUISetBkColor(0x01A1F7)
$FILES_DROPPED = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)
#EndRegion ###
GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES_FUNC')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $FILES_DROPPED
$aFiles = $gaDropFiles
_change_bip()
EndSwitch
WEnd
Func _change_bip()
$file = FileOpen($aFiles[0], 512)
$read = FileRead($file)
_ReplaceStringInFile($read, "version 9", "version 7") ;!!!!!!!!!!!!!!!!
EndFunc
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 0)
ReDim $gaDropFiles[$nAmt[0]]
For $i = 0 To $nAmt[0] - 1
$nSize = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', 0, 'int', 0)
$nSize = $nSize[0] + 1
$pFileName = DllStructCreate('wchar[' & $nSize & ']')
DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', DllStructGetPtr($pFileName), 'int', $nSize)
$gaDropFiles[$i] = DllStructGetData($pFileName, 1)
$pFileName = 0
Next
GUICtrlSendToDummy($FILES_DROPPED, $nAmt[0])
EndFunc
Alles anzeigen