ptrex Posted June 14, 2005 Posted June 14, 2005 Hello, Is there a function available, once a file is read to an array. That the result is shown in reverse order (I mean bottum up). This is the code ; Read in lines of text until the EOF is reached While 1 $i = 0 Do $line = FileReadLine($file) $i = $i + 1 Until $i = 6 If @error = -1 Then ExitLoop $string = StringSplit($line, " ", 0) Dim $avArray[10] $avArray[0] = $string[1] $avArray[1] = $string[2] $avArray[2] = $string[3] $avArray[3] = $string[4] $avArray[4] = $string[5] $avArray[5] = $string[6] $avArray[6] = $string[7] $avArray[7] = $string[8] $avArray[8] = $string[9] $avArray[9] = $string[10] ;_ArrayReverse($avArray) $data=$avArray[0]&"|"&$avArray[1]&"|"&$avArray[2]&"|"&$avArray[3]&"|"&$avArray[4]&"|"&$avArray[5]&"|"&$avArray[6]&"|"&$avArray[7]&"|"&$avArray[8]&"|"&$avArray[9] $dataCol=GUICtrlCreateListViewItem($data,$listview) Wend I experimented with "Array Sort Decending/Ascending". But is is not showing what I want. Once the data is in the 10 dimentions of the array. I would like to sort it by $avArray[0] and that all the other dimensions follow accordingly. A work around could be that I read the file bottem up, instead of top down. Is that the solution ? Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
Valuater Posted June 14, 2005 Posted June 14, 2005 A work around could be that I read the file bottem up, instead of top down.Is that the solution ?thats probably the easiest... and..I dont see a $string[0]that has a value alsogood luck8)
JSThePatriot Posted June 14, 2005 Posted June 14, 2005 I have created a UDF that you are more than welcome to use. Let me know if it is what you want. It reverses the contents of any file you input. Just copy and paste below into SciTE and run it. The message box at the top is just an example of how to call the function. MsgBox(0, "Test Reversing", _FileReadReverse("output.txt")) Func _FileReadReverse($s_File = "") Local $file, $s_Chars, $s_bChars Local $a_Chars Local $i If $s_File = "" Then MsgBox(0, "Error", "Please supply a path when using this function") SetError(1) Return -1 EndIf $file = FileOpen($s_File, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file: output.txt") SetError(1) Return -1 EndIf $s_Chars = FileRead($file, FileGetSize($s_File)) FileClose($file) $a_Chars = StringSplit($s_Chars, "") For $i = $a_Chars[0] To 1 Step -1 $s_bChars = $s_bChars & $a_Chars[$i] Next If $s_bChars = "" Then Return -1 Else Return $s_bChars EndIf EndFunc JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
ptrex Posted June 14, 2005 Author Posted June 14, 2005 Thanks for the feedback. I will try this tomorrow and let you all know the result. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
/dev/null Posted June 14, 2005 Posted June 14, 2005 #include <Array.au3> $filename = "C:\test.txt" $file = FileOpen($filename,0) $lines = FileRead($file,FileGetSize($filename)) FileClose($file) $newlines = StringReplace($lines, CHR(10), " ") $rev = StringSplit($newlines, " ") _ArrayDisplay($rev,"") _ArrayReverse($rev) _ArrayDisplay($rev,"") or this #include <Array.au3> $filename = "C:\test.txt" $file = FileOpen($filename,0) $lines = FileRead($file,FileGetSize($filename)) FileClose($file) $rev = StringSplit($newlines, CHR(13)) _ArrayDisplay($rev,"") _ArrayReverse($rev) _ArrayDisplay($rev,"") might need some "adjustment" Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
JSThePatriot Posted June 15, 2005 Posted June 15, 2005 #include <Array.au3> $filename = "C:\test.txt" $file = FileOpen($filename,0) $lines = FileRead($file,FileGetSize($filename)) FileClose($file) $newlines = StringReplace($lines, CHR(10), " ") $rev = StringSplit($newlines, " ") _ArrayDisplay($rev,"") _ArrayReverse($rev) _ArrayDisplay($rev,"")or this #include <Array.au3> $filename = "C:\test.txt" $file = FileOpen($filename,0) $lines = FileRead($file,FileGetSize($filename)) FileClose($file) $rev = StringSplit($newlines, CHR(13)) _ArrayDisplay($rev,"") _ArrayReverse($rev) _ArrayDisplay($rev,"")might need some "adjustment"CheersKurt<{POST_SNAPBACK}>Nice. I didnt know there was an _ArrayRevers() function as I havent even used any of the _Array*() functions.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
ptrex Posted June 15, 2005 Author Posted June 15, 2005 @all Thanks for the replies and support. I have tested all of them and non of them run smoothly. this means when starting it will use 100% of the CPU for a long time and the PC is practically locked. So I will have find a way that the script is in some way limited in using all the recources. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
/dev/null Posted June 15, 2005 Posted June 15, 2005 I have tested all of them and non of them run smoothly.this means when starting it will use 100% of the CPU for a long time and the PC is practically locked.Erm... How large ist the file exactly you are reading?CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
ptrex Posted June 15, 2005 Author Posted June 15, 2005 @dev/null/ The file is about 3,5 Mb large. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
JSThePatriot Posted June 15, 2005 Posted June 15, 2005 @dev/null/The file is about 3,5 Mb large.<{POST_SNAPBACK}>Hrm... you might try...MsgBox(0, "Test Reversing", _FileReadReverse("output.txt")) Func _FileReadReverse($s_File = "") Local $file, $s_Chars, $s_bChars Local $a_Chars Local $i If $s_File = "" Then MsgBox(0, "Error", "Please supply a path when using this function") SetError(1) Return -1 EndIf $file = FileOpen($s_File, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file: output.txt") SetError(1) Return -1 EndIf $s_Chars = FileRead($file, FileGetSize($s_File)) FileClose($file) $a_Chars = StringSplit($s_Chars, "") For $i = $a_Chars[0] To 1 Step -1 $s_bChars = $s_bChars & $a_Chars[$i] Sleep(100) Next If $s_bChars = "" Then Return -1 Else Return $s_bChars EndIf EndFuncI added a sleep in the loop that reverses. I think it should reduce CPU usage. I am not sure that it can be optimized any other way. I will keep looking.JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
/dev/null Posted June 15, 2005 Posted June 15, 2005 @dev/null/The file is about 3,5 Mb large.<{POST_SNAPBACK}>3,5 MB?? You should have mentioned that before. Obviously it does not make ANY sense to do it like this for such a large file. The only way to do it is to read the file line by line "backwards". That might help to speed up the process. Anyway, probably you want to explain why you want to reverse the file, maybe, there is another solution for your problem.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
/dev/null Posted June 15, 2005 Posted June 15, 2005 I have tested all of them and non of them run smoothly.this means when starting it will use 100% of the CPU for a long time and the PC is practically locked.I tested my second alternative again, and it was quite fast, even with 4 MB (5 seconds). BUT, you cannot call _ArrayDisplay(), as this will run forever. Without _ArrayDisplay() it take ~5 seconds.#include <Array.au3> $filename = "C:\test.txt" $file = FileOpen($filename,0) $lines = FileRead($file,FileGetSize($filename)) FileClose($file) $rev = StringSplit($newlines, CHR(13)) ; _ArrayDisplay($rev,"") ; DON'T do this with large arrays _ArrayReverse($rev) ;_ArrayDisplay($rev,""); DON'T do this with large arraysMy first alternative takes forever, while executing the command StringReplace for such a large string.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
herewasplato Posted June 15, 2005 Posted June 15, 2005 _ArrayReverse($rev) uses this loop to copy the array:; Copy the elements in the array till $i_Base For $iIndex1 = 0 To $i_Base - 1 $avArray[$iIndex1] = $avNewArray[$iIndex1] Next The help file mentions this: A unique feature is the ability to copy arrays like this: $mycopy = $myarray Is there a reason to use a loop? Just wondering.... [size="1"][font="Arial"].[u].[/u][/font][/size]
ptrex Posted June 16, 2005 Author Posted June 16, 2005 @all I tested the _ArrayReverse($rev) but it is not helping me out. Because it will reorder the data in the Array, and not reorder the sequence of the lines. See Help: "Takes the given array and reverses the order in which the elements appear in the array" What I need is that after the lines are read, the sequence of the lines need to be reversed. Last line need to come first, before last line needs to come second, ... PS: The _arrayReverse runs indead fast, the is no CPU overload. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
herewasplato Posted June 16, 2005 Posted June 16, 2005 I really do not know what you are attempting to do here, but hopefully you can find some code that is of use to you from the stuff below. expandcollapse popup; for a text file containing these lines: ; this is line one of the file to be read ; this is the second line ; and the third line ; a forth line just for fun $filename = "";<<<<<<<<<<<<<add filename and/or path $file = FileOpen($filename,0) $aArray = StringSplit(FileRead($file,FileGetSize($filename)),@LF) FileClose($file) ; output of lines of code above ; $aArray [0] = 4 ; $aArray [1] = this is line one of the file to be read ; $aArray [2] = this is the second line ; $aArray [3] = and the third line ; $aArray [4] = a forth line just for fun ;it can be displayed (used) in that order For $i = 1 to (UBound($aArray) - 1) MsgBox(0,"$aArray [" & $i & "]",$aArray[$i]) Next ;it can be displayed (used) in reverse order For $i = (UBound($aArray) - 1) to 1 Step -1 MsgBox(0,"$aArray [" & $i & "] - shown reversed",$aArray[$i]) Next ; copy array to a new one - just to DIM the new array $anewArray = $aArray ;it can be reversed within another array For $i = 1 to (UBound($anewArray) - 1) $anewArray[UBound($anewArray) - $i] = $aArray[$i] Next ; output of lines of code above ; $anewArray [0] = 4 ; $aArray [1] = a forth line just for fun ; $aArray [2] = and the third line ; $aArray [3] = this is the second line ; $aArray [4] = this is line one of the file to be read For $i = 1 to (UBound($anewArray) - 1) MsgBox(0,"$anewArray [" & $i & "]",$anewArray[$i]) Next [size="1"][font="Arial"].[u].[/u][/font][/size]
ptrex Posted June 16, 2005 Author Posted June 16, 2005 @herewasplato The Ubound($array) option 2, did it !! Since there is no SORT option available in the LISTVIEW GUI. I tried to simulate this by clicking a button and then sorting the data accordingly. Maybe in the future this will integrated in the LISTVIEW control. Thanks a lot !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
roy Posted June 16, 2005 Posted June 16, 2005 @all Try this solution derived from Unix world that I found after a little search on the internet and traslated into AutoIt. I tried this method on a very large file and it is very fast. Follow the instruction in the source code. Enjoy!. Roy CreateReverseFile.au3
ptrex Posted June 17, 2005 Author Posted June 17, 2005 @Rov Thanks for your contribution. I will give it a try later on, because my application needs to run that same with the same file. Your trick is making first a new file and than use that reversed file to work on. It might be good in for some other occations. But it' s a nice tip anyway. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
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