| View previous topic :: View next topic |
| Author |
Message |
Gust Voice
Joined: 28 Jun 2006 Posts: 15
|
Posted: Tue Aug 21, 2007 2:07 pm Post subject: |
|
|
OK, very old topic but still problems...
With the code for reading a whole file:
| Code: | set fname "textfile.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"] |
my bot just reads the first line...
How to solve that? |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Aug 21, 2007 5:49 pm Post subject: |
|
|
You sure it only read 1 line? How are you trying to determine what's in the $data var after reading in the file?
If you do:
| Code: |
foreach line [split $data \n] {
putcmdlog "line '$line'"
}
|
you should see all of the data and some blank lines?
When I read/write to files, I check for blank lines and exclude them along the way:
| Code: |
# read data in
if {![file exists $quotefile]} {return "No quotes available."}
set quotelines ""
set inqfile [open $quotefile r]
set quotetemp [split [read $inqfile] \n]
catch {close $inqfile}
foreach line $quotetemp {
if {$line != ""} {
lappend quotelines $line
}
}
|
| Code: |
# write data out
set quotewrite [open $quotefile w]
foreach line $quotelines {
set line [string trim $line]
if {$line != ""} {
puts $quotewrite $line
}
}
catch {close $quotewrite}
|
|
|
| Back to top |
|
 |
|