+ readingFile:do:
authorClaus Gittinger <cg@exept.de>
Mon, 11 Feb 2002 10:19:44 +0100
changeset 6382 9e658e5b5734
parent 6381 30003c4c5908
child 6383 1197f9507ad2
+ readingFile:do:
Filename.st
--- a/Filename.st	Wed Feb 06 20:12:42 2002 +0100
+++ b/Filename.st	Mon Feb 11 10:19:44 2002 +0100
@@ -560,6 +560,53 @@
     "Created: / 19.5.1999 / 12:24:26 / cg"
 !
 
+readingFile:aPathName do:aBlock
+    "create a read-stream on a file, evaluate aBlock, passing that stream,
+     and return the blocks value.
+     Ensures that the stream is closed."
+
+    |stream result|
+
+    stream := aPathName asFilename readStream.
+    [
+        result := aBlock value:stream
+    ] ensure:[
+        stream close
+    ].
+    ^ result
+
+    "
+     |rslt|
+
+     rslt := Filename 
+                readingFile:'/etc/passwd' 
+                do:[:s |
+                    Transcript showCR:s nextLine
+                ].
+    "
+
+    "
+     Filename 
+         readingFile:'/etc/passwd' 
+         do:
+             [:s |
+                 |shells|
+
+                 shells := Bag new.
+                 s linesDo:
+                     [:line |
+                         |parts|
+
+                         parts := line asCollectionOfSubstringsSeparatedBy:$:.
+                         shells add:(parts seventh).
+                     ].
+                 shells contents
+             ].           
+    "
+
+    "Modified: / 31.10.2001 / 09:25:45 / cg"
+!
+
 remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames
     "create & return a new filename from components given in
      aCollectionOfDirectoryNames on a host named remoteHostString. 
@@ -4171,6 +4218,6 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.208 2001-12-06 16:51:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.209 2002-02-11 09:19:44 cg Exp $'
 ! !
 Filename initialize!