class: Filename
authorClaus Gittinger <cg@exept.de>
Fri, 04 Sep 2015 14:38:55 +0200
changeset 18734 91cf1b39b479
parent 18733 20fc1bb8fe15
child 18735 681996ef7e51
child 18737 20f867a78d54
class: Filename added: #filesWithSuffix: #filesWithSuffix:do: comment/format in: #filesDo: changed: #files
Filename.st
--- a/Filename.st	Fri Sep 04 10:32:38 2015 +0200
+++ b/Filename.st	Fri Sep 04 14:38:55 2015 +0200
@@ -2234,16 +2234,13 @@
 !
 
 files
-    "return a collection of files contained in the directory represented by the receiver."
+    "return a collection of regular files   
+     contained in the directory represented by the receiver."
 
     |collection|
 
     collection := OrderedCollection new.
-    self directoryContentsAsFilenamesDo:[:eachFileName |
-	eachFileName isRegularFile ifTrue:[
-	    collection add:eachFileName
-	].
-    ].
+    self filesDo:[:eachFileName | collection add:eachFileName].
     ^ collection.
 
     "
@@ -2254,10 +2251,13 @@
 !
 
 filesDo:aBlock
-    "evaluate aBlock for all files contained in the directory represented by the receiver."
+    "evaluate aBlock for all regular files (i.e. subdirs are ignored)
+     contained in the directory represented by the receiver."
 
     ^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
-	eachFileOrDirectory isRegularFile ifTrue:[ aBlock value: eachFileOrDirectory].
+        eachFileOrDirectory isRegularFile ifTrue:[ 
+            aBlock value: eachFileOrDirectory
+        ].
     ].
 
     "
@@ -2268,6 +2268,40 @@
     "Modified: / 29-05-2007 / 12:02:46 / cg"
 !
 
+filesWithSuffix:suffix
+    "return a collection of regular files (i.e. not subdirectories)
+     with a given suffix which are contained in the directory 
+     represented by the receiver."
+
+    |collection|
+
+    collection := OrderedCollection new.
+    self filesWithSuffix:suffix do:[:eachFileName | collection add:eachFileName].
+    ^ collection.
+
+    "
+     '.' asFilename filesWithSuffix:'so'.
+    "
+!
+
+filesWithSuffix:suffix do:aBlock
+    "evaluate aBlock for all regular files with a given suffix
+     contained in the directory represented by the receiver.
+     (i.e. subdirs are ignored)"
+
+    ^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
+        (eachFileOrDirectory hasSuffix:suffix) ifTrue:[
+            eachFileOrDirectory isRegularFile ifTrue:[ 
+                aBlock value: eachFileOrDirectory
+            ].
+        ].
+    ].
+
+    "
+     '.' asFilename filesWithSuffix:'so' do:[:f | Transcript showCR:f].
+    "
+!
+
 recursiveDirectoryContentsAsFilenamesDo:aBlock
     "evaluate aBlock for all files and directories found under the receiver.
      The block is invoked with the filenames as argument.