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 

id number per file

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


Joined: 06 Nov 2006
Posts: 255

PostPosted: Sun Nov 09, 2008 8:01 pm    Post subject: id number per file Reply with quote

hello i have one proc that:


set g_last2 [linsert $g_last2 end $g_lastinfo]
set fileio [open /home/ultralord/www/g_last2.txt "w"]
puts $fileio $g_last2
flush $fileio
close $fileio


that creates one txt file with name g_last2 .. i want w8 that proc run's second time then i want to create txt file with name g_last201 .. is it possible?

01=id number and after that 02.. etc..


thnx in advance
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Nov 09, 2008 8:57 pm    Post subject: Reply with quote

I'd suggest you store a counter in some global variable, say file_counter, and use something like this:
Code:
#instantiate the file_counter variable upon load
set file_counter 0

...
proc yourproc ....
 set fileio [open "/home/ultralord/www/g_last2[format "%02u" [incr ::file_counter]]" "w"]
...


Here we use incr to increase the value of the counter upon every iteration of the code, and then format to achieve the desired 2-digit format with padding zeros.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Sun Nov 09, 2008 9:17 pm    Post subject: Reply with quote

thnx Surprised i found another way yo do my job Razz

i make some procs more and i make same expr and done..

thanks that will be very usefull in the future

also. how i can resolve the id when i rehash my bot if i use it?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Nov 10, 2008 8:55 pm    Post subject: Reply with quote

Resolve? Could you please elaborate that a bit?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Tue Nov 11, 2008 5:03 am    Post subject: Reply with quote

if i rehash or restart the bot the counter number will be 0 and then will be start count again from begging ..
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Nov 11, 2008 11:17 am    Post subject: Reply with quote

Ohh, you meant restore..
Well, one way would be to include code to (re)write a simple tcl-script (loaded from your script once it completes) which basically sets the variable to the previous value...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
game_over
Voice


Joined: 26 Apr 2007
Posts: 29

PostPosted: Tue Nov 11, 2008 12:18 pm    Post subject: Reply with quote

I know another way
Code:
set directory "txts/"
#only txt files :)
set pattern "*.txt"

if {[catch {glob "${directory}${pattern}"} files]} {
   return "No files in this dir"
} else {
   if {[string match "*[info script]*" $files]} {
      set listOffilesInThistDir [expr [llength $files] -1]
   }
   }


now when you know filecount you script newfile to $listOffilesInThistDir + 1 Smile
Back to top
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Thu Nov 20, 2008 8:22 am    Post subject: Reply with quote

good try Smile also if you can make another proc and you can put one number like 1 1 1 1 and when you rehash the bot the variable read how many times you have the number 1 1 1 1 into a txt file and then you have your latest id number . Idea
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