help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] walking a directory tree


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] walking a directory tree
Date: Fri, 09 Jan 2009 10:44:46 +0100
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Sean Allen wrote:
> 
> On Jan 9, 2009, at 3:58 AM, Paolo Bonzini wrote:
> 
>>> if i do:
>>> file :=  File name: '/Users/Spooneybarger'
>>> file all do: [ :e | e isDirectory ifTrue: [ e directories printNl ]  ]
>
> What am I doing wrong?

"file all do:" is doing an "ls -lR" which is already slow. :-)

Since without my patch "e" is in turn a RecursiveFileWrapper (the kind
of object returned by #all), each send of #directories in the block
would in turn invoke a recursive descent.  So that's a loop of "ls -lR"s
inside an "ls -lR", and it's going to take a while. :-)  Actually it's
going to be infinite, because sooner or later you'll do "e directories"
on "/Users/Spooneybarger/..".

With my patch, first of all "e" is a normal File so you have a loop of
"ls" inside an "ls -lR", and it's a bit faster.  Second, "." and ".."
are not passed by "file all do:"; this matches the behavior of the
command-line utility "find", for example (they're still passed by "file
do:", which matches "ls -a").

Note that the output of

  file all directories do: [ :each | each printNl ]

and

  file all do: [ :e | e isDirectory ifTrue: [ e directories printNl ]  ]

is different.  Suppose you have

  /a
  /a/b
  /a/c
  /a/c/d

the first will print (more or less) exactly that.  The latter would
print several Arrays (each with the list of subdirectories in each
directory) which will be:

  (/a/. /a/.. /a/b /a/c)
  (/a/b/. a/b/..)
  (/a/c/. a/c/.. /a/c/d)
  (/a/c/d/. a/c/d/..)

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]