Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding all files in a directory

9 views
Skip to first unread message

August Karlstrom

unread,
Jun 3, 2007, 1:50:02 PM6/3/07
to
Hi everyone,

What is the standard way in TCL to get a list of all files in a
directory and its subdirectories?


Regards,

August

Darren New

unread,
Jun 3, 2007, 2:00:22 PM6/3/07
to
August Karlstrom wrote:
> What is the standard way in TCL to get a list of all files in a
> directory and its subdirectories?

package require fileutil
fileutil::find

(Requires Tcllib installed.)

--
Darren New / San Diego, CA, USA (PST)
His kernel fu is strong.
He studied at the Shao Linux Temple.

August Karlstrom

unread,
Jun 3, 2007, 2:41:44 PM6/3/07
to
Darren New wrote:
> August Karlstrom wrote:
>> What is the standard way in TCL to get a list of all files in a
>> directory and its subdirectories?
>
> package require fileutil
> fileutil::find
>
> (Requires Tcllib installed.)
>

Works like a charm. Thanks.


August

Cameron Laird

unread,
Jun 3, 2007, 2:24:31 PM6/3/07
to
In article <466301b3$0$1363$4c36...@roadrunner.com>,

Darren New <dn...@san.rr.com> wrote:
>August Karlstrom wrote:
>> What is the standard way in TCL to get a list of all files in a
>> directory and its subdirectories?
>
>package require fileutil
>fileutil::find
>
>(Requires Tcllib installed.)
.
.
.
Keep in mind a couple of factors that reduce the scariness
common with "requires X installed":
A. ActiveTcl, now widely used, provides Tcllib;
and
B. the current copy of fileutil.tcl is under 700
lines of pure-Tcl, and that includes a lot of
comments, so it's not hard to just pull in a
copy of *that* alone, if you prefer (note,
though, that fileutil itself requires cmdline).

Tom Conner

unread,
Jun 4, 2007, 1:57:51 AM6/4/07
to

"August Karlstrom" <fusio...@comhem.se> wrote in message
news:ebD8i.1254$ZA....@newsb.telia.net...

> Hi everyone,
>
> What is the standard way in TCL to get a list of all files in a
> directory and its subdirectories?
>

glob

http://www.tcl.tk/man/tcl8.4/TclCmd/glob.htm

I have to admit, that is one non-intuitive command name. One would think
there would be a "file" command that accomplishes that task.


bill...@alum.mit.edu

unread,
Jun 4, 2007, 2:58:38 AM6/4/07
to
fileutil::find is useful but it is an extension, not a "standard", and
does more than the OP needs. The glob command, which is part of the
core, is the standard way to list all files in a directory.

suchenwi

unread,
Jun 4, 2007, 4:15:35 AM6/4/07
to
On 4 Jun., 07:57, "Tom Conner" <tcon...@olopha.net> wrote:
> glob
>
> http://www.tcl.tk/man/tcl8.4/TclCmd/glob.htm
>
> I have to admit, that is one non-intuitive command name. One would think
> there would be a "file" command that accomplishes that task.

Well, it's a C standard library function:
The glob() function is a pathname generator that implements the rules
for file name pattern matching used by the shell.

See e.g. http://www.hmug.org/man/3/glob.php

Donal K. Fellows

unread,
Jun 4, 2007, 4:23:47 AM6/4/07
to

The original poster asked for "all files in a directory and its
subdirectories"; so fileutil::find is absolutely the right thing.

Donal.

iu2

unread,
Jun 4, 2007, 8:54:53 AM6/4/07
to

I like for_recursive_glob from Tclx (there is also just
recursive_glob).

bill...@alum.mit.edu

unread,
Jun 4, 2007, 11:08:13 AM6/4/07
to
On Jun 4, 1:23 am, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:

Ah, that depends on whether the OP's request contains an implicit
"recursively".
If it does, yes, fileutil::find is right. If it doesn't, glob * */*
does the job.

Bill

August Karlstrom

unread,
Jun 4, 2007, 4:24:40 PM6/4/07
to

You are right, after rereading my posting I realise I should have added
the word "recursively".

Thank you all for your helpful answers.


August

0 new messages