Jump to content
Sign in to follow this  
leuce

Please help with FileReadLIne

Recommended Posts

leuce

Hello everyone

Please can anyone tell me what's wrong with this script?

#include <File.au3>

#cs

Trim list to 250 characters

#ce

$fileo = FileOpen ("list.txt", 32)

$filer = FileRead ($fileo)

$count = _FileCountLines (@ScriptDir & "\list.txt")

$filew = FileOpen ("list2.txt", 33)

For $i = 1 to $count

$line = FileReadLine ($filer, $i)

MsgBox (0, "", $line, 0)

$len = StringLen ($line)
$len2 = $len - 250

$foo = StringTrimRight ($line, $len2)

FileWrite ($filew, $foo)

Next

The "list.txt" is a plain text file with a few lines of text in it.  It's suppose to give me a MsgBox with each line in it.  But I get blank MsgBox'es, and the output file list2.txt is empty.  I've tried other "list.txt" files, and I've tried different file encodings.

Thanks

Samuel

Share this post


Link to post
Share on other sites
Chimp

try this way

#include <File.au3>

#cs

Trim list to 250 characters

#ce

$fileo = FileOpen ("list.txt", 32) ; read mode

; $filer = FileRead ($fileo) ; ?? not needed

$count = _FileCountLines (@ScriptDir & "\list.txt")

$filew = FileOpen ("list2.txt", 33) ; write mode

For $i = 1 to $count

$line = FileReadLine ($fileo) ; read next line

MsgBox (0, "", $line)

$len = StringLen ($line)
$len2 = $len - 250

$foo = StringTrimRight ($line, $len2)

FileWrite ($filew, $foo) ; maybe you need FileWriteLine ?

Next

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
mikell

Why not simply FileReadToArray ?

Edited by mikell

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.