Jump to content

Delete Line from text File


Jat421
 Share

Recommended Posts

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...