Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 05-24-2005, 08:31 AM   #1
djdeluxe76
Member
 
Join Date: Mar 2005
Posts: 43
Default I need a hand with some TCL proc...

Hello and thanks for coming here...

First off, this is my first attempt at TCL scripting. I have been reading
thru the ActiveTCL manuals alot lately. Now I am trying to build a proc
that will do the following:

open a channel "in"
read in some logfiles in a dir "logdir"
close channel "in"
foreach of these files read them and lappend to a variable "log_data"
open a new channel "out" and puts the collected (read) $log_data
then close channel "out"
return with the logfile argument of this proc that was used as file for the open "out"]

So in the end I have a file "logfile" created by "out" that contains all
the data read by "in". And I have the ability to store the return code by
the proc in a new variable so I can work with the location of "logfile".

Here's what I have so far:

Code:
proc savePrelog {dir logfile} {
   set prelog_data {}
   foreach file [glob -nocomplain -directory $dir *{underdogs}*.log] {

	 set line [gets $in]
	 set dataIN [read $in]

      close $in

      lappend prelog_data $dataIN

      set out [open $logfile a]
      set dataOUT $prelog_data

      puts $out $dataOUT

      close $out

   }
   return $logfile
}
but this way I have the problem that it does not stop once it has
read all logfiles. The saved file just grows and grows...
There must be a way to do this properly.

Thanks for any replies

Cheers
DJ
djdeluxe76 is offline  
Old 05-24-2005, 01:04 PM   #2
Harm
Too much time...
Ultimate Scripter
 
Join Date: Jul 2003
Posts: 1,430
Default

You're right for the second file, you need to open the data stream / file before reading anything from it. Also "gets" will only read one line from the file (starting where the current file pointer is). You can use "read" instead ; it'll read the whole file. I have also added a "-types f" switch to the "glob" command to make sure all files are files and not directories (or anything else).

I guess "underdog" appears in all the names of the logfiles you want to merge.

Code:
proc savePrelog {dir logfile} {
   set data ""
   set logfiles [glob -nocomplain -directory $dir -types f -- "*underdogs*.log"]
   foreach logfile $logfiles {
      set in [open $logfile r]
      set data [read $in]
      close $in
      set out [open $logfile a]
      puts $out $data
      close $out
   }
   return $logfile
}
I hope this helps.
Good luck
Harm is offline  
Old 05-24-2005, 03:09 PM   #3
djdeluxe76
Member
 
Join Date: Mar 2005
Posts: 43
Thumbs up

Gee, thanks Harm, that actually helps a lot!
Working with it now...

Yea, you assume correctly, "underdogs" appears in all file names.

I'm all excited to make it work, let's go back coding

Cheers
DJ
djdeluxe76 is offline  
Closed Thread

Tags
channel, file, proc, read, set


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:23 PM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)