On Mon, 2007-01-08 at 23:03 -0700, J Pfersich wrote:
> I have a question about the behavior of two methods in Directory.
> I get this from filesMatching:
> st> var2 filesMatching: 'test*' do: [:file | ( file name) display.
> st>                                          ', ' display.
> st>                                          file printNl ] !
> /Users/johnp/projects/smalltalk/gnu/test.st, a File
> /Users/johnp/projects/smalltalk/gnu/testing, a Directory
> /Users/johnp/projects/smalltalk/gnu/testing3, a Directory
> 
> and I get this from allFilesMatching:
> var2 allFilesMatching: 'test*' do: [:file | (file name) display.
> st>                                        ', ' display.
> st>                                        file printNl] !
> /Users/johnp/projects/smalltalk/gnu/test.st, a File
> /Users/johnp/projects/smalltalk/gnu/testing3/testing3-file, a File
> /Users/johnp/projects/smalltalk/gnu/testing3/testing3-file-2, a File
> 
> Shouldn't they produce the same objects? I mean either all files and 
> directories or just files?

The first one is correct; after all, a Directory is a File, and those
directories are "in" .../gnu/.  allFilesMatching:do: does seem like it
should call its block with a superset of those found by
filesMatching:do:, though.

Attached is a patch that implements this behavior by modifying
Directory>>allFilesMatching:do:.

-- 
Stephen Compall
http://scompall.nocandysw.com/blog
2007-01-09  Stephen Compall  <[EMAIL PROTECTED]>

	* kernel/Directory.st (allFilesMatching:do:): Pass Directory
	entries to aBlock if they match aPattern.

--- orig/kernel/Directory.st
+++ mod/kernel/Directory.st
@@ -206,13 +206,12 @@
 
     self do: [ :name || f | 
 	f := self at: name.
+	(aPattern match: name)
+	    ifTrue: [ aBlock value: f ].
 	f isDirectory 
 	    ifTrue: [
 		((#('.' '..') includes: name) or: [ f isSymbolicLink ])
 		    ifFalse: [ f allFilesMatching: aPattern do: aBlock ] ]
-	    ifFalse: [
-		(aPattern match: name)
-		    ifTrue: [ aBlock value: f ] ] ]
 !
 
 contents

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to