| View previous topic :: View next topic |
| Author |
Message |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Sun Nov 09, 2008 8:01 pm Post subject: id number per file |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Nov 09, 2008 8:57 pm Post subject: |
|
|
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 |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Sun Nov 09, 2008 9:17 pm Post subject: |
|
|
thnx i found another way yo do my job
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Nov 10, 2008 8:55 pm Post subject: |
|
|
Resolve? Could you please elaborate that a bit? _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Tue Nov 11, 2008 5:03 am Post subject: |
|
|
| 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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Nov 11, 2008 11:17 am Post subject: |
|
|
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 |
|
 |
game_over Voice
Joined: 26 Apr 2007 Posts: 29
|
Posted: Tue Nov 11, 2008 12:18 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Thu Nov 20, 2008 8:22 am Post subject: |
|
|
good try 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 .  |
|
| Back to top |
|
 |
|