egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Basic File Operations

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Gust
Voice


Joined: 28 Jun 2006
Posts: 15

PostPosted: Tue Aug 21, 2007 2:07 pm    Post subject: Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Tue Aug 21, 2007 5:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber