Jump to content

Is it possible to read a .txt file line by line using the InetRead function


Recommended Posts

I have a txt file on dropbox. In the txt file as follows: 

1 | 2 | 3 | 4 | 5

6 | 7 | 8 | 9 | 10

...

How can now read it as Filereadline() using InetRead() function

Link to post
Share on other sites
  • Developers

My translation of this cryptic question is that there is a file on the Dropbox Website that the OP likes to download with InetGet() ... but that will never work.
Maybe one of the Other Web tools out there could do the job.
 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

On the PC with Dropbox client installed right click the file you want to download for further processing -> "copy dropbox link" (German: "Dropbox-Link kopieren")

You will receive something like this real world URL (I created and shared a file for you in my Dropbox:

https://www.dropbox.com/s/oagfd0e314pz3a0/Some-foo-file.txt?dl=0

Replace the 0 at it's end with a 1:

https://www.dropbox.com/s/oagfd0e314pz3a0/Some-foo-file.txt?dl=1

#include <Inet.au3>

$URL="https://www.dropbox.com/s/oagfd0e314pz3a0/Some-foo-file.txt?dl=1"
$Content = _INetGetSource($URL)
MsgBox(0,"Content",$Content)

Then use StringSplit() as mentioned by @junkew

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites
Posted (edited)

This is how i did it but can you help me to read this return data line by line?
Example: Read line 1 then
$Data[0][0] = 1
$Data[0][1] = a
$Data[0][n] = ...
$Data[1][0] =2
$Data[1][1] = e
$Data[1][n] = ...
$Data[2][0] = 3
$Data[2][1] = x
$Data[3][n] = ...

#include <InetConstants.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <Array.au3>

Local $ReadData = InetRead("http://dl.dropboxusercontent.com/s/h73t2gvwkercmab/Test.txt")

$Data = BinaryToString($ReadData)
_ArrayDisplay(StringSplit($Data, '|', $STR_ENTIRESPLIT))

Please excuse my English!

Edited by Loc
Link to post
Share on other sites
Posted (edited)

1.) InetGetSource() will directly return STRING data (no need to use BinaryToString())

2) Use StringSplit() to just split the lines. You split to a 2D array: @crlf delimits lines, | delimits collumns.

 

#include <Inet.au3>
#include <Debug.au3>


$URL="https://www.dropbox.com/s/oagfd0e314pz3a0/Some-foo-file.txt?dl=1"
$Content = _INetGetSource($URL)
MsgBox(0,"Content",$Content)

$aLines=StringSplit($Content,@CRLF,1)
_DebugArrayDisplay($aLines)

for $L = 1 to $aLines[0]
    MsgBox(0,"Line " & $L,$aLines[$L])
Next

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

Well, this is now spoon feeding IMHO -- never mind 😇

 

#include <Inet.au3>
#include <Debug.au3>

$URL = "http://dl.dropboxusercontent.com/s/h73t2gvwkercmab/Test.txt"
$Content = _INetGetSource($URL)
MsgBox(0, '', $Content)
$aLines = StringSplit($Content, @CRLF,1) ; The first element will hold the number of chunks the sting $Content was split to
_DebugArrayDisplay($aLines)

For $L = 1 To $aLines[0]
    MsgBox(0,"Line = " & $L,$aLines[$L])
Next

the last but one line is the position where you need to process the separated lines.

 

The rest of the work is now up to you...

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...