Jat421 Posted September 14, 2010 Share Posted September 14, 2010 Hi, I have a function that reads a line from a text file. Now the issue I am having is that once that line is read I want to delete that line from the file. Below is what I have so far, but it doesn't seem to work. I am using the WinAPI because I want to lock the text file while reading it. Thanks for any help!! Func ReadWrite() $tBuffer = DllStructCreate("byte[16]") $hFile = _WinAPI_CreateFile($File1, 2, 6, 0) _WinAPI_SetFilePointer($hFile, 0) _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 16, $nBytes) $sText = "" $wBuffer = DllStructCreate("byte[" & StringLen($sText) & "]") DllStructSetData($wBuffer, 1, $sText) $hFile = _WinAPI_CreateFile($hFile, 2, 6, 0) _WinAPI_WriteFile($hFile, DllStructGetPtr($wBuffer), StringLen($sText) , $nBytes) _WinAPI_CloseHandle($hFile) $sText = BinaryToString(DllStructGetData($tBuffer, 1)) ClipPut($sText) $c = @UserName $k = _FileWriteLog($File2, " " & $stext & " " & $c) MsgBox(0, "Number is", $sText) EndFunc The File1 looks like this 1234567891234567 1234567891234568 1234567891234569 1234567891234566 1234567891234562 Link to comment Share on other sites More sharing options...
wakillon Posted September 14, 2010 Share Posted September 14, 2010 See this post it can help you for doing same thing by another way ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Jat421 Posted September 14, 2010 Author Share Posted September 14, 2010 Hi, Thanks for the link. But I believe I will not be able to pass the handle to that _FileLineDelete() in the UDF. I can probably do it by writing a different function with this UDF but then the text file will not be locked when I am writing to it. I would like to lock the text file while it's been read and written to. Anything else you can suggest. Thanks for your help!! Link to comment Share on other sites More sharing options...
wakillon Posted September 15, 2010 Share Posted September 15, 2010 Is the _ReplaceStringInFile( ) function could help you ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Jat421 Posted September 15, 2010 Author Share Posted September 15, 2010 I will give that a try but I have a feeling that might not work. I will I need a WinAPI call to get the handle. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now