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

is "ls" a cross-platform Tcl command?

1,173 views
Skip to first unread message

Giovanni Flammia

unread,
Jul 25, 1996, 3:00:00 AM7/25/96
to fla...@sls.lcs.mit.edu

Hello:

I think this problem is similar to deleting a file. I would like
to put a directory listing into a Tcl list variable
and make a listbox out of it, without running "exec ls", so that
it runs smoothly on other platforms. I'd like to do something simple...

if {[file isdirectory $f]} {
set listing [ls $f]
}

Is it possible? To my knowledge, ls is a Unix and DOS command,
but not a native Tcl command. Is that right?

Giovanni Flammia

Brian Stoler

unread,
Jul 25, 1996, 3:00:00 AM7/25/96
to Giovanni Flammia

Giovanni Flammia wrote:
> to put a directory listing into a Tcl list variable
> and make a listbox out of it, without running "exec ls", so that
> it runs smoothly on other platforms. I'd like to do something simple...

I believe the command you are looking for is glob. Use it like this:

set listing [glob /path/to/your/dir/*]

--
/-----------------\
| Brian Stoler |
| br...@feith.com |
\-----------------/

J.M. Ivler

unread,
Jul 26, 1996, 3:00:00 AM7/26/96
to

Giovanni Flammia (fla...@sls.lcs.mit.edu) wrote:
: Hello:
:
: if {[file isdirectory $f]} {
: set listing [ls $f]
: }

you have tried the glob command, right?

Jeffrey Hobbs

unread,
Jul 26, 1996, 3:00:00 AM7/26/96
to

In article <31F80A4C...@sls.lcs.mit.edu>,

Giovanni Flammia <fla...@sls.lcs.mit.edu> wrote:
>to put a directory listing into a Tcl list variable
>and make a listbox out of it, without running "exec ls", so that

You want the 'glob' command in general. If you ever desire something
that is cross platform with more of the capabilities of 'ls', you can
look at the one in TkCon (http://www.cs.uoregon.edu/~jhobbs/work/tkcon/).

--
Jeffrey Hobbs Office: 541/346-3998
Univ of Oregon CIS GRF email: jho...@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~jhobbs/

Jesper Pedersen

unread,
Jul 26, 1996, 3:00:00 AM7/26/96
to Giovanni Flammia

In article <31F80A4C...@sls.lcs.mit.edu>,

Giovanni Flammia <fla...@sls.lcs.mit.edu> writes:
>Hello:

>I think this problem is similar to deleting a file. I would like

>to put a directory listing into a Tcl list variable
>and make a listbox out of it, without running "exec ls", so that

>it runs smoothly on other platforms. I'd like to do something simple...

You may use the Tcl command glob instead.
Kind Regards Jesper.


Robert Heller

unread,
Jul 27, 1996, 3:00:00 AM7/27/96
to

Giovanni Flammia <fla...@sls.lcs.mit.edu>,
In a message on Thu, 25 Jul 1996 19:59:08 -0400, wrote :

GF> Hello:
GF>
GF> I think this problem is similar to deleting a file. I would like
GF> to put a directory listing into a Tcl list variable
GF> and make a listbox out of it, without running "exec ls", so that
GF> it runs smoothly on other platforms. I'd like to do something simple...
GF>
GF> if {[file isdirectory $f]} {
GF> set listing [ls $f]
GF> }
GF>
GF> Is it possible? To my knowledge, ls is a Unix and DOS command,

Just a Unix command, not a *native* MS-DOS command

GF> but not a native Tcl command. Is that right?

Yes. You don't need to use ls to get a directory listing. Tcl does have a
builtin for this:

if {[file isdirectory $f]} {
set listing [glob -nocomplain $f/*]
}

will give you the results you want and will won't on any platform -- Unix,
MS-DOS (-Windows), and MaxOS.


--
\/
Robert Heller ||InterNet: Hel...@CS.UMass.EDU
http://vis-www.cs.umass.edu/~heller ||FidoNet: 1:321/153
http://netmar.com/mall/shops/heller /\

0 new messages