tommytx 0 Posted April 28, 2011 (edited) Is there a commmand in autoit like in php for example to get the entire text file into a single variable such as: Php cmd -> $dog = file_get_contents("test.txt") this would do fine but not available in Autoit... The only thing I could find was as follows: Seems like going around your elbow to get to your thumb. _FileReadToArray("test.txt", $x) (bring text file into array) $y = _ArrayToString($x) (now take the array to a variable) $z = StringSplit($y, "|") (So I can split it at the separator.) Did I not look hard enough? *************************** File will look like this one line per item. text.txt dog| cat| hat| bat| $x array looks like this $x[0] = 4 $x[1] = dog| $x[2] = cat| $x[3] = hat| $x[4] = bat| $ y variable will end up looking like this. $y = "dog|cat|hat|bat|" _FileReadToArray("test.txt", $x) $y = _ArrayToString($x, @TAB, 1, 7)) $z = StringSplit($y, "|") Actually the dog, cat hat and bat represent all the lines in an html file which is complex and each section of the html file is marked with the symbol | For example: |1039498.htm 668 LUTHER STREET |Chesapeake, VIRGINIA 23322 |152000 |3 |HOME HAS VIEWS OF BELLS MILL LAKE. UPDATED THROUGHOUT, NEWER CABINETS, COUNTERS, BATHS. WOOD FLOORS |Chesapeake |VA | <center> <h2><font color=red>Click Photo for More Details</font></b></h2> <a href="http://www.mydomain.com/craig/details.php?idxID=163&listingID=1039498" rel="nofollow"> <img src="http://www.other.com/photos/rein/8/9/1039498.JPG" width="520" height="390" border="0" style=""></a><br> <a href="http://www.mydomain.com/craig/moreInfo.php?idxID=163&listingID=1039498" rel="nofollow">More Information</a> | <a href="http://www.mydomain.com/craig/showing.php?idxID=163&listingID=1039498" rel="nofollow">Schedule Showing</a> | <a href="http://www.mydomain.com/craig/mortgage.php?idxID=163&listingID=1039498&price=152000" rel="nofollow">Calculator</a> | <a href="http://maps.google.com/maps?q=36.7193510,+-76.2627630" target="_blank" rel="nofollow">Map Location</a> | <a href="mailto:?subject=I found a property and wanted to share it with you!&body=This is the link to the property I found:%0A%0Ahttp://search.mydomain.com/idx/6210/details.php%3FidxID%3D163%26listingID%3D1039498%0A%0AWhat do you think?">Email Property</a><br><br> <a href="http://www.mydomain.com/craig/photoGallery.php?idxID=163&listingID=1039498" rel="nofollow">View Photo Gallery(9)</a><br><br> <font color="red"><h2>Price: $152,000</h2></font> </center> Edited April 28, 2011 by tommytx Share this post Link to post Share on other sites
Melba23 3,498 Posted April 28, 2011 tommytx,Try FileRead. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Share this post Link to post Share on other sites
kaotkbliss 146 Posted April 28, 2011 (edited) Check out FileOpen and FileRead *edit* Doh, too slow. Edited April 28, 2011 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011010010110011100100001My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueekWe're gonna need another Timmy! Share this post Link to post Share on other sites
tommytx 0 Posted April 28, 2011 $file = FileOpen("test.txt", 0) ; Read in 1 character at a time until the EOF is reached While 1 $chars = FileRead($file, 1) Wend FileClose($file) Thanks but I am well aware of fileread.. I just cannot believe that with all the neat bells and whistles, Autoit does not have a simple 1 line load the file to a variable as does most other languages. Wow! Look at all the code to do a simple job... They do allow a one line load file to array so makes sense to have a one line load to variable.. But if you guys say.. No.. then i guess the command does not exist. (Worse yet.. that loads 1 character at a time.) It would probably be better to load at least one full line at a time using filereadline .... Share this post Link to post Share on other sites
Melba23 3,498 Posted April 28, 2011 (edited) tommytx,Of course you can do it in one line: $chars = FileRead("test.txt")Just read the parameter values:filehandle/filename The handle of a file, as returned by a previous call to FileOpen. Alternatively you may use a string filename as the first parameter. count [optional] The number of characters to read. Default read the entire file.So use the filename and use the default "entire file" value for the count.Easy when you actually read the Help file instead of complaining about the language! M23Edit: Formatting went funny. Edited April 28, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Share this post Link to post Share on other sites
hannes08 39 Posted April 28, 2011 (edited) Thanks but I am well aware of fileread.. I just cannot believe that with all the neat bells and whistles, Autoit does not have a simple 1 line load the file to a variable as does most other languages.Wow! Look at all the code to do a simple job...They do allow a one line load file to array so makes sense to have a one line load to variable..But if you guys say.. No.. then i guess the command does not exist. (Worse yet.. that loads 1 character at a time.)It would probably be better to load at least one full line at a time using filereadline ....Did you ever try to code ABAP? Thinking about pain in the ass handling files... ANYTHING is easier. Edited April 28, 2011 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Share this post Link to post Share on other sites
BrewManNH 1,306 Posted April 28, 2011 @tommytx You do realize that the way you wrote it that the only value that the variable $chars would ever hold is the last character read? Just before the script craps out because you're reading it inside an endless loop that is. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Share this post Link to post Share on other sites