Sign in to follow this  
Followers 0
tommytx

Is there a cmd to load an entire text file at once?

7 posts in this topic

#1 ·  Posted (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&amp;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&amp;listingID=1039498" rel="nofollow">More Information</a> | 
<a href="http://www.mydomain.com/craig/showing.php?idxID=163&amp;listingID=1039498" rel="nofollow">Schedule Showing</a> | 
<a href="http://www.mydomain.com/craig/mortgage.php?idxID=163&amp;listingID=1039498&amp;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!&amp;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&amp;listingID=1039498" rel="nofollow">View Photo Gallery(9)</a><br><br>
<font color="red"><h2>Price: $152,000</h2></font>
</center>
Edited by tommytx

Share this post


Link to post
Share on other sites



tommytx,

Try FileRead. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Check out FileOpen and FileRead :unsure:

*edit*

Doh, too slow.

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

$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

#5 ·  Posted (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! ;)

M23

Edit: Formatting went funny. :unsure:

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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... :unsure:

ANYTHING is easier. :>

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

@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 Gude
How 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

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