foster74 Posted February 13, 2009 Share Posted February 13, 2009 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 =( Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Share Posted February 13, 2009 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 Link to comment Share on other sites More sharing options...
foster74 Posted February 13, 2009 Author Share Posted February 13, 2009 use fileopen($File,2)This will open the file in non -appending mode, and will delete all previous lines.. in a secThank you, but I am only looking to delete the first line, and this deletes all content of the file. =/ Link to comment Share on other sites More sharing options...
Manjish Posted February 13, 2009 Share Posted February 13, 2009 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 Link to comment Share on other sites More sharing options...
Inverted Posted February 13, 2009 Share Posted February 13, 2009 (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 February 13, 2009 by Inverted Link to comment Share on other sites More sharing options...
BrettF Posted February 13, 2009 Share Posted February 13, 2009 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Aceguy Posted February 13, 2009 Share Posted February 13, 2009 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) [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
picaxe Posted February 13, 2009 Share Posted February 13, 2009 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) Link to comment Share on other sites More sharing options...
Inverted Posted February 13, 2009 Share Posted February 13, 2009 Wow, picaxe's method is very quick. I changed the script to this barebones example : $Timer = TimerInit() $text = FileRead("C:\originalfile.txt") FileWrite("c:\modified.txt", StringTrimLeft($text, StringInStr($text, @CRLF) +1)) msgbox(0,"Test", TimerDiff($Timer)) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now