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.

How many Files in Folder?

Help for those learning Tcl or writing their own scripts.
Post Reply
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

How many Files in Folder?

Post by Access »

I want to know how many files with ending *.moep are in /filebase/ folder...

How? ^^ (Too short? dont know how to explain...)



2nd question - no extra thread:

how to delete all files with ending *.moep in /filebase/ folder...?
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

for the first question:

Code: Select all

set filenum 0
foreach entry [glob -directory /filebase/ *.moep] {
  incr filenum
}
return $filenum
and for the second:

Code: Select all

foreach entry [glob -directory /filebase/ *.moep] {
  file delete $entry
}
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Post by Access »

very nice! thx!
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Why use incr?

Code: Select all

proc filecount {file} {
  return [llength [glob -nocomplain $file]]
}
Could be used with [filecount /home/myuser/*.something]
Post Reply