Jump to content
Sign in to follow this  

Delete Line from text File

Recommended Posts


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)
    $sText = BinaryToString(DllStructGetData($tBuffer, 1))
    $c = @UserName                                          
    $k = _FileWriteLog($File2, " " & $stext & " " & $c)     
    MsgBox(0, "Number is", $sText)                      

The File1 looks like this


Share this post

Link to post
Share on other sites

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!!

Share this post

Link to post
Share on other sites

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!

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...