Sign in to follow this  
Followers 0
ffdshow

Get links from a .txt file

5 posts in this topic

#1 ·  Posted (edited)

I have a text file which contains one link per line, but the links are prefixed and suffixed with some characters.

The suffixes are not a problem since they all contains exactly 20 characters. Prefixes contains different number of characters.

Example:

ghjgrjd.rar;http://www.netload.in/dateiGivoLSefgq/ghjgrjd.rar.htm;100 MB;2;31.05.2010
wrdrtv.rar;http://www.netload.in/dateixXm3I1wopv/wrdrtv.rar.htm;100 MB;2;31.05.2010

The problem is that the prefixes have different length from line to line and a script like this

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
While 1
$line = FileReadLine($inputfile)
If @error Then ExitLoop
$result = StringTrimLeft($line, 12)
If StringLen($line) = 0 Then FileWriteLine ($outputfile, "")
If StringLen($line) > 0 Then FileWriteLine ($outputfile, $result)
Wend
FileClose ($inputfile)
FileClose ($outputfile)

will not help.

Is possible to extract all links to a text file (one link per line) ?

Edited by ffdshow

Share this post


Link to post
Share on other sites

If those semicolons are consistent, use StringSplit.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

One possibility might be this:

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
Global $o
While 1
    $line = FileReadLine($inputfile)
    If @error Then ExitLoop
    $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1)
    If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF
Wend
FileWrite($outputfile, $o)
FileClose ($inputfile)
FileClose ($outputfile)

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks UEZ! Works fine.

Share this post


Link to post
Share on other sites

One possibility might be this:

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
Global $o
While 1
    $line = FileReadLine($inputfile)
    If @error Then ExitLoop
    $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1)
    If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF
Wend
FileWrite($outputfile, $o)
FileClose ($inputfile)
FileClose ($outputfile)

BR,

UEZ

This code example was useful to me as well; thanks very much.

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