Sign in to follow this  
Followers 0
Champak

Delete blank/empty line without writing to second file

3 posts in this topic

#1 ·  Posted (edited)

Finding and deleting the line is not a problem, but the blank space left behind is. I really don't want to bother with writing to a second file, deleting and renaming the file. So is it possible to go through and remove the blank line like you do when looking for an actual string? Prefer, but not a must, to not bother with an array for this.

#include <File.au3>

$find = "Test Line"
$replace = ""
$filename = "C:\Test.txt"
_ReplaceStringInFile($filename,$find,$replace)
Edited by Champak

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Found a way...if someone knows a better way please post.

$fileread = "testfile.txt"
$lines = _FileCountLines($fileread)
$hold = ""
For $x = 1 to $lines
    $search= FileReadLine($fileread, $x)
    If $search <> "" Then
        $hold&= $search & @CRLF
    EndIf
Next
FileDelete($fileread)
FileWrite($fileread, $hold)
Edited by Champak

Share this post


Link to post
Share on other sites

do string replace, like here #463031


"be smart, drink your wine"

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