leuce Posted June 21, 2016 Posted June 21, 2016 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
Gianni Posted June 21, 2016 Posted June 21, 2016 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
mikell Posted June 22, 2016 Posted June 22, 2016 (edited) Why not simply FileReadToArray ? Edited June 22, 2016 by mikell
HurleyShanabarger Posted June 22, 2016 Posted June 22, 2016 Like this? ;Read file to array Dim $aFile = FileReadToArray("list.txt") If @error Then Exit ;Open write file $hFile = FileOpen("list2.txt", 33) ;Loop through array and write line by line For $i = 0 To UBound($aFile)-1 FileWriteLine($hFile, StringLeft($aFile[$i], 250)) Next ;Close write file FileClose($hFile)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now