This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

listing files in a directory

Old posts that have not been replied to for several years.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

listing files in a directory

Post by Pitchat »

HI

i want to know if it is possible to do via a public command and a dcc command a listing of the files that are in a specific directory of my eggdrop.

exemple : i use my eggdrop to display text files that are poems so i`d like for the user to type something like !poems or !list to have access to the listings of the files that are in my poems directory

note that i`m using a windrop not a linux version

any idea are welcome

thanks

Pitchat
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Use something like: 'catch { glob -type f dir/* } files' to get the files names in that 'files' variable.
Once the game is over, the king and the pawn go back in the same box.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

can you help me for the beginning i`m quite new and it is difficult for me to make a structure from scratch since it is my second or third tcl that i make

thanks
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Shure, here you go:

Code: Select all

set poemsdir "path/to/poems"

bind pub * !poems pub:poems

proc pub:poems {nick host handle channel text} {
catch { glob -type f $::poemsdir/* } poems
regsub -all "$::poemsdir/" $poems "" poems
putserv "PRIVMSG $channel :\002Poems\002: $poems"
}
Once the game is over, the king and the pawn go back in the same box.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

[02:06] (@Precieuse): Poems: no files matched glob pattern "*"

this is what my eggy say when i type !poems in channel

any idea why ?

the $poemsdir seems to be set correctly so i dont see why it doesnt show the listing of the text files in that dir

thanks
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Are you shure that dir exists? I've did a test and put a *wrong* dir name and got the same result as you did, so review the settings and be shure it's the right dir name.
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Also, add this

Code: Select all

if {![file exists $::poemsdir]} {
putserv "PRIVMSG $channel :\002Error\002: $::poemsdir dose not exist."
return 0
}
before the 'catch { glob -type f $::poemsdir/* } poems' and try the !poems again.
Once the game is over, the king and the pawn go back in the same box.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

my txt files are located on c:\precieuse\histoires

( yes i`m french speaking :) )

and i set the poemsdir like this

set poemsdir "/precieuse/histoires/"
and i stille receive that same error

my dir is loaded with .txt files
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

this is how the scripts loo like after modification and i still recieved the error

Code: Select all

set poemsdir "/precieuse/histoires/" 

bind pub * !poems pub:poems 

proc pub:poems {nick host handle channel text} { 
if {![file exists $::poemsdir]} { 
putserv "PRIVMSG $channel :\002Error\002: $::poemsdir dose not exist." 
return 0 
}
catch { glob -type f $::poemsdir/ } poems 
regsub -all "$::poemsdir/*" $poems "" poems
putserv "PRIVMSG $channel :\002Histoires\002: $poems" 
} 
i`m lost
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

catch { glob -type f $::poemsdir/ } poems

You seem to have forgotten a * on that line, it should be:

catch { glob -type f $::poemsdir/* } poems
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

U are right now it works
my mistake....

now is there a way to make the list more "esthetic" it display all filenames one after another on the same line and i`d like to have it one fileneme by line

i know i`m pulling my luck a lot :D
thank you very much for your patience and for sharing your knowledge

Pitchat
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Bordome will prevail

Code: Select all

set poemsdir "/precieuse/histoires/" 
set peomlimit 7

bind pub * !poems pub:poems 

proc pub:poems {nick host handle channel text} { 
  if {![file exists $::poemsdir]} { 
    putserv "PRIVMSG $channel :\002Error\002: $::poemsdir dose not exist." 
    return 0 
  } 
  catch { glob -type f $::poemsdir/ } poems 
  regsub -all "$::poemsdir/*" $poems "" poems 
  set first [list]
  foreach item $poems {
    if {[llength $first] == $::peomlimit} {
      putserv "PRIVMSG $channel :\002Histoires\002: [string trimright [join $first ", "] ", "]"
      set first [list]
    }
    lappend fist $item
  }
  if {[length $first]} {
    putserv "PRIVMSG $channel :\002Histoires\002: [string trimright [join $first ", "] ", "]"
  }
}
Change the "set peomlimit" line, to the amount of peoms you wish to display on a single line.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

[03:47] Tcl error [pub:poems]: invalid command name "length"

:oops:
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Don't worry, my fault, hoenst.

I am waiting for Slennox to install the coffee machine facility here, as I need it badly :P

Look though the code for "[length $first]". Near the bottom of the code.

Change it to "[llength $first]". Note the extra/missing l.
P
Pitchat
Op
Posts: 122
Joined: Tue Feb 18, 2003 11:24 pm
Location: Hebertville Quebec Canada
Contact:

Post by Pitchat »

it is worst now the bot crashes

Code: Select all

set poemsdir "/precieuse/histoires/" 
set peomlimit 7 

bind pub * !histoire pub:poems 

proc pub:poems {nick host handle channel text} { 
  if {![file exists $::poemsdir]} { 
    putserv "PRIVMSG $channel :\002Error\002: $::poemsdir dose not exist." 
    return 0 
  } 
  catch { glob -type f $::poemsdir/ } poems 
  regsub -all "$::poemsdir/*" $poems "" poems 
  set first [list] 
  foreach item $poems { 
    if {[llength $first] == $::peomlimit} { 
      putserv "PRIVMSG $channel :\002Histoires\002: [string trimright [join $first ", "] ", "]" 
      set first [list] 
    } 
    lappend fist $item 
  } 
  if {[llength $first]} { 
    putserv "PRIVMSG $channel :\002Histoires\002: [string trimright [join $first ", "] ", "]" 
  } 
it`s the whole code including the latest change you gave me

now the error message

<Precieuse> [04:07] Tcl error in file 'config.txt':
<Precieuse> [04:07] wrong # args: should be "proc name args body"
[04:07] (Precieuse): while executing
[04:07] (Precieuse): "proc pub:poems {nick host handle channel text} {
[04:07] (Precieuse): if {![file exists $::poemsdir]} {
[04:07] (Precieuse): putserv "PRIVMSG $channel :\002Error\002: $::poemsdir dose ..."
[04:07] (Precieuse): (file "scripts/listing2.tcl" line 6)

thanks
P.S. i could use some of that coffee myself :)[/quote]
Locked