Sign in to follow this  
Followers 0
faustf

file remove line inside txt

6 posts in this topic

hi guy i  have  questions   :)

i  saw  is possible read line  by line ,  and write line  by line  , but  how  is possible cancel line  by  line ??

i must  write in the same line  a blank line ?? if  yes  what is  a command  for  tell at autoit  , blanck line??

thankz at all 

Share this post


Link to post
Share on other sites



Not enough info...

How big is the file?

Do you want to delete the line or blank it out (two very different things)?


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

suppose  you have this  file  txt

www.mysite.comindex.html

www.mysite.comindex.html

www.mysite.comindex.html

www.mysite.comindex.html

i want cancel the  first line    how  is possible do ???

thankz

Share this post


Link to post
Share on other sites

Providing you know what line number, do as JohnOne suggested.

If not, then you may need to use line testing and writing to another file, which gets renamed to the original afterward.

With a uniquely named line, you could just use _ReplaceStringInFile

All options above, bearing in mind, what kylomas asked too.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hi guy at end  i  have  birth this  code  , for me,  work good,  but  probably  is not good  style :D

if  someone  want  corret  is  welcome 

Func _File_DeleteLine_Shift($path, $line)

    If $line = "" Then
        $line = 1
    EndIf
    _FileReadToArray($path, $aArray)
    Local $iDelete = FileDelete($path)
    $file = FileOpen($path, 1)

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    Else

        For $i = 0 To UBound($aArray) - 1 ; Loop through the array.

            If $i = $line Then
                ;MsgBox (0,'', $aArray[$i])
            Else
                If $aArray[$i] = 34 Then

                Else
                    FileWrite($file, $aArray[$i] & @CR)
                EndIf

            EndIf
        Next

    EndIf

    ; Close the handle returned by FileOpen.
    FileClose($file)
EndFunc   ;==>_File_DeleteLine_Shift 

thankz at  all 

Edited by faustf

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  
Followers 0