Sign in to follow this  
Followers 0
foster74

Any faster ways to delete a line then to use _FileWriteToLine?

9 posts in this topic

It takes around 8 seconds to delete the first line of a 900,000 line file using _FileWriteToLine. Even with smaller files the time taken is too long for my current project. Any ideas? Thanks very much in advance.

#include<file.au3>
$Timer = TimerInit()
$File = "C:\Documents and Settings\Myself\My Documents\test.txt";900,000 Line file
_FileWriteToLine($File, 1, "",1);Deletes First line of File
msgbox(0,"Test", TimerDiff($Timer));Timer shows it takes around 8 seconds =(

Share this post


Link to post
Share on other sites



use fileopen($File,2)

This will open the file in non -appending mode, and will delete all previous lines.. in a sec


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

use fileopen($File,2)

This will open the file in non -appending mode, and will delete all previous lines.. in a sec

Thank you, but I am only looking to delete the first line, and this deletes all content of the file. =/

Share this post


Link to post
Share on other sites

well i don't know.. but the script timer, shows that the script executes in 2 secs.. n to tell u the truth i timed it using a stopwatch timer.. it was definately around 2 secs.. i dunno, y timerinit shows 8 secs.. but it sure doesn't feel like 8 secs..


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

well i don't know.. but the script timer, shows that the script executes in 2 secs.. n to tell u the truth i timed it using a stopwatch timer.. it was definately around 2 secs.. i dunno, y timerinit shows 8 secs.. but it sure doesn't feel like 8 secs..

And how did you test this ?

You don't have the same 900,000 lines file as the original poster !! And you don't have the same PC and operating system.

Lol ?!?

Edited by Inverted

Share this post


Link to post
Share on other sites

I'll be trying some things shortly, at the moment I'm generating a file like so:

$file = FileOpen ("filename.txt", 2)
For $i = 0 To 900000
    ConsoleWrite ($i & @CRLF)
;Generate a random string of numbers
    $string = Random (0, 10, 1)
    $string &= Random (0, 10, 1)
    $string &= Random (0, 10, 1)
    $string &= Random (0, 10, 1)
    $string &= Random (0, 10, 1)
    FileWriteLine ($file, $string)
Next

FileClose ($file)

I imagine you can use StringRegExp which should be faster.

I believe someone did something with it, so have a search... :)

Cheers,

Brett

Share this post


Link to post
Share on other sites

Seriously 900,000 lines..... like err what the hell is that file...

i thinik with a file that size, 8 seconds to perform a task like that is good.

here is what i came up with but done in 7... so sorry, not much of an improvement.

#Include <File.au3>
#include <array.au3>
#Include <Timers.au3>
$timer=_Timer_Init()

dim $myarray

$file = _FileReadToArray (@DesktopDir&"\filename.txt",$myarray)
_FileWriteFromArray(@DesktopDir&"\filename2.txt",$myarray,2,0)

ConsoleWrite(_Timer_Diff($timer)/1000)

Share this post


Link to post
Share on other sites

Time to read/delete 1st line/write on my system 1.69sec

$file1 = "900.txt"
If FileExists($file1) Then FileDelete($file1)
$file2 = "900-1.txt"
If FileExists($file2) Then FileDelete($file2)
$j = ""
For $i = 1 To 900000
    $j &= "This is line " & $i & " This is line " & $i & " This is line " & $i & " This is line " & $i & @CRLF
Next
FileWrite($file1, $j)
$start1 = TimerInit()
$text = FileRead("900.txt")
ConsoleWrite("file read time=" & Round(TimerDiff($start1)/1000, 2) & "sec" & @LF)
$start2 = TimerInit()
FileWrite("900-1.txt", StringTrimLeft($text, StringInStr($text, @CRLF) +1))
ConsoleWrite("delete line time=" & Round(TimerDiff($start2)/1000, 2) & "sec" & @LF)
ConsoleWrite("total time=" & Round(TimerDiff($start1)/1000, 2) & "sec" & @LF)

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