From: S-Y. Chen on
Hi there,

I am wondering if there is a way to list the names (or getting the
names into a list) of all directories under the current directory ?

I am just trying to process all files under all directory under the
current directory. Any help will be greatly appreciated.

Regards
S-Y. Chen


























From: Alan Grunwald on
S-Y. Chen wrote:
>
> I am wondering if there is a way to list the names (or getting the
> names into a list) of all directories under the current directory ?
>
> I am just trying to process all files under all directory under the
> current directory. Any help will be greatly appreciated.
>

If you use [glob] to get a list of all the files in the directory, and
then use [file isdirectory] to determine which of those files are
directories, you shouldn't go far wrong.

Good luck
--
Alan
From: Gerald W. Lester on
Alan Grunwald wrote:
> S-Y. Chen wrote:
>>
>> I am wondering if there is a way to list the names (or getting the
>> names into a list) of all directories under the current directory ?
>>
>> I am just trying to process all files under all directory under the
>> current directory. Any help will be greatly appreciated.
>>
>
> If you use [glob] to get a list of all the files in the directory,
> and then use [file isdirectory] to determine which of those files are
> directories, you shouldn't go far wrong.

A little reading of the glob man/help page shows that glob also takes a
-types option whose values can control what type (e.g. directories) of files
it will return.


--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Bruce on
S-Y. Chen wrote:
> Hi there,
>
> I am wondering if there is a way to list the names (or getting the
> names into a list) of all directories under the current directory ?
>
> I am just trying to process all files under all directory under the
> current directory. Any help will be greatly appreciated.
>
> Regards
> S-Y. Chen
>

http://tcllib.sourceforge.net/doc/fileutil.html

specifically look at fileutil::find

Bruce
From: Spam on
On Sun, 16 May 2010, S-Y. Chen wrote:

> Date: Sun, 16 May 2010 03:14:59 -0700 (PDT)
> From: S-Y. Chen <shenyeh_chen(a)hotmail.com>
> Newsgroups: comp.lang.tcl
> Subject: Getting the names of all directories
>
> Hi there,
>
> I am wondering if there is a way to list the names (or getting the
> names into a list) of all directories under the current directory ?
>
> I am just trying to process all files under all directory under the
> current directory. Any help will be greatly appreciated.
>
> Regards
> S-Y. Chen


Here are a couple of simple procs which might be of some small assistance
no warranty, no refunds, no nothing ...

#
# return all files in a given directory ...
proc listFiles { D } {
set typ {f r}
set fls [ glob -nocomplain -directory $D -type $typ -- * ]
set ret [list]
foreach f $fls {
lappend ret [file tail $f]
}
return [lsort $ret ]
}

#
# return a list of directories within a path ...
proc listTree {{dir .}} {
set res {}
lappend res $dir
foreach i [lsort [glob -nocomplain -dir $dir -- *]] {
if {[file type $i]=="directory"} {
lappend res $i
eval lappend res [listTree $i]
}
}
set res [ lsort -unique $res ]
return $res
}


HTH,
Rob Sciuk