[Top][All Lists]

[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 07:16:54 +0100
User-agent: Thunderbird (Macintosh/20081209)

Sean Allen wrote:
> i did see anything like this but, before i go ahead and code it,
> i thought i would check to make sure i didn't miss anything.
> is there a method to enumerate through all entries in a directory,
> all the way down.. ( not just the top level in a directory )


  (File name: 'foo') allFilesMatching: aPattern do: aBlock

the "aPattern" has to be in the same syntax as String>>#match:, so ? is
replaced by # and * works as in the shell.

Or you can use #all the same as I was suggesting for chown:

  (File name: 'foo') all do: [ :file | ]
  (File name: 'foo') all namesDo: [ :string | ]
  (File name: 'foo') all filesMatching: aPattern do: aBlock
  (File name: 'foo') all namesMatching: aPattern do: aBlock

FilePath>>#all is documented, albeit a bit cryptically:

        Return a decorator of the receiver that will provide recursive
        descent into directories for iteration methods.

Regarding your other message, Directory is present for backwards
compatibility.  Everything it implemented has already been moved to
FilePath or File.  Otherwise, navigating a filesystem like above would
have implied a "stat" system call for every file, to know whether to
create a File or Directory instance.

Directory still has a few class methods, most of which create instances
of File but were left there because those instances are always
directories (e.g. "Directory home").

I updated the class comment and will regenerate the manual in a couple
of hours.  Thanks for your work again, every stumbling of yours will
make GST a better product for others to learn.

> Or are we supposed use in this fashion?
> file := File name: '/Users/Spooneybarger'
> file isDirectory ifTrue: [ file directories ]



reply via email to

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