Jump to content
Sign in to follow this  
Marius

Any ideas?

Recommended Posts

Marius

#include <File.au3>

$test = "C:\test.txt"

msgbox(4096, "Info", "Deleting Last 4 lines  ")
$lastline = _FileCountLines($test)
FileDelLine($test, $lastline-3, $lastline) 

msgbox(4096, "Info", "Deleting line 2  ")
FileDelLine($test, 2, 2) 

func FileDelLine($file, $start_line, $end_line)

  local $tmpfile = _TempFile()

  local $fh = FileOpen ( $file, 0)
  local $fh_tmp = FileOpen ( $tmpfile, 2 )
  local $cur_line = 0

  while 1
    $line = FileReadLine($fh)
    $cur_line = $cur_line + 1
    if @error = -1 then
       FileClose($fh)
       FileClose($fh_tmp)
       FileDelete($file)
       FileMove($tmpfile, $file)
       return
    endif 

    if ($cur_line < $start_line) or ($cur_line > $end_line) then
       FileWriteLine($fh_tmp, $line)
    endif 
  wend
endfunc

Any ideas how to leave blank lines of deleted text? :)


Marius back in da hood! :)

Share this post


Link to post
Share on other sites
HardCopy

#include <File.au3>

$test = "C:\test.txt"

msgbox(4096, "Info", "Deleting Last 4 lines  ")
$lastline = _FileCountLines($test)
FileDelLine($test, $lastline-3, $lastline) 

msgbox(4096, "Info", "Deleting line 2  ")
FileDelLine($test, 2, 2) 

func FileDelLine($file, $start_line, $end_line)

  local $tmpfile = _TempFile()

  local $fh = FileOpen ( $file, 0)
  local $fh_tmp = FileOpen ( $tmpfile, 2 )
  local $cur_line = 0

  while 1
    $line = FileReadLine($fh)
    $cur_line = $cur_line + 1
    if @error = -1 then
       FileClose($fh)
       FileClose($fh_tmp)
       FileDelete($file)
       FileMove($tmpfile, $file)
       return
    endif 

    if ($cur_line < $start_line) or ($cur_line > $end_line) then
       FileWriteLine($fh_tmp, $line)
    endif 
  wend
endfunc

Any ideas how to leave blank lines of deleted text?  :)

<{POST_SNAPBACK}>

not to sure if this is to simple...but why not instead of deleting lines replace the text with a NULL string

HardCopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites
Valuater

good idea hardcopy

8)


NEWHeader1.png

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  

×