aommaster Posted December 24, 2008 Share Posted December 24, 2008 Hi guys! The code is below: $basefile=fileopen("start.txt", 0) while (@error <>-1) $string=filereadline($basefile) if (@error <>-1) then filewriteline($outputfile, $string) WEnd fileclose($basefile) I was just wondering if there was a way of making this code slightly more efficient. I don't like the if (@error <>-1) parts. Thanks guys Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 24, 2008 Share Posted December 24, 2008 Hi, do you want to have a FileCopy? Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
GEOSoft Posted December 24, 2008 Share Posted December 24, 2008 Hi guys! The code is below: $basefile=fileopen("start.txt", 0) while (@error <>-1) $string=filereadline($basefile) if (@error <>-1) then filewriteline($outputfile, $string) WEnd fileclose($basefile) I was just wondering if there was a way of making this code slightly more efficient. I don't like the if (@error <>-1) parts. Thanks guys $basefile=fileopen("start.txt", 0) If @Error <> -1 Then while 1 $string=filereadline($basefile) if not @Error then filewriteline($outputfile, $string) WEnd EndIf If $Basefile Then fileclose($basefile) As a side note, there is no slower method to read a file than using FileReadLine() George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
aommaster Posted December 24, 2008 Author Share Posted December 24, 2008 Hi, do you want to have a FileCopy? Mega Nah.. there's more to the program than that. It's just the start. $basefile=fileopen("start.txt", 0) If @Error <> -1 Then while 1 $string=filereadline($basefile) if not @Error then filewriteline($outputfile, $string) WEnd EndIf If $Basefile Then fileclose($basefile) As a side note, there is no slower method to read a file than using FileReadLine() Ahh.. well, my final text file is supposed to look like this: Header Main Body Footer The header and the footer are always the same (hence, the use of these loops to copy the respective parts to the final output file). The Main body changes with respect to the input. Doesn't look like there's a file copy to the end of file function, is there? Thanks Link to comment Share on other sites More sharing options...
Bowmore Posted December 24, 2008 Share Posted December 24, 2008 Try this. I don't have access to autoit to check it myself just now $outputfile=fileopen("output.txt") $basefile=fileopen("start.txt", 0) $string=filereadline($basefile) while (@error <> -1) filewriteline($outputfile, $string) $string=filereadline($basefile) WEnd fileclose($basefile) fileclose($outputfile) "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
aommaster Posted December 24, 2008 Author Share Posted December 24, 2008 Absolutely brilliant. Thanks Bowmore! Link to comment Share on other sites More sharing options...
Zedna Posted December 24, 2008 Share Posted December 24, 2008 More speed efficient way: $data=FileRead("start.txt") $data=StringSplit($data,@CRLF,1) $outputfile=fileopen("output.txt",2) For $i=1 To $data[0] $string=$data[$i] filewrite($outputfile, $string) Next fileclose($outputfile) Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 24, 2008 Share Posted December 24, 2008 More speed efficient way: $data=FileRead("start.txt") $data=StringSplit($data,@CRLF,1) $outputfile=fileopen("output.txt",2) For $i=1 To $data[0] $string=$data[$i] filewrite($outputfile, $string) Next fileclose($outputfile)oÝ÷ Ûú®¢×ׯzy¨æ®¶sbb33c·4FFÒfÆU&VBgV÷C·7F'BçGBgV÷C²¢b33c¶FFÒ7G&æu7ÆBb33c·4FFÂ5$Äb ¢b33c·4FFÒgV÷C²gV÷C° ¤f÷"b33c¶ÒFòb33c¶FF³Ð¢b33c·4FFf׳Òb33c¶FF²b33c¶Òfײ5$Ä`¤æW@ ¢b33c¶fÆT÷VâÒfÆT÷VâgV÷C¶÷WGWBçGBgV÷C²Â"¤fÆUw&FRb33c¶fÆT÷VâÂb33c·4FF¤fÆT6Æ÷6Rb33c¶fÆT÷Vâ Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
aommaster Posted December 24, 2008 Author Share Posted December 24, 2008 Hehe.. thanks for the input everyone 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