--- a/Filename.st Tue Apr 26 20:30:11 2016 +0200
+++ b/Filename.st Wed Apr 27 14:58:53 2016 +0200
@@ -2315,7 +2315,7 @@
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)."
self recursiveDirectoryContentsDo:[:relFn |
- aBlock value:(self construct:relFn)
+ aBlock value:(self construct:relFn)
].
"
@@ -2333,7 +2333,10 @@
Subdirectory files are included with a relative pathname.
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)."
- self recursiveDirectoryContentsDo:aBlock directoryPrefix:''
+ self
+ recursiveDirectoryContentsWithPrefix:''
+ filesDo:aBlock
+ directoriesDo:aBlock
"
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
@@ -2347,37 +2350,14 @@
The block is invoked with a string-argument.
The walk is breadth-first.
This excludes any entries for '.' or '..'.
- Subdirectory files are included with a relative pathname.
+ The argument to aBlock is a pathname relative to aPrefix.
A proceedable exception is raised forn non-accessible directories.
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)."
- |fileNames dirNames p|
-
- fileNames := OrderedCollection new.
- dirNames := OrderedCollection new.
- self directoryContentsDo:[:f | |t|
- t := self construct:f.
- t isDirectory ifTrue:[
- t isSymbolicLink ifFalse:[
- dirNames add:f
- ]
- ] ifFalse:[
- fileNames add:f
- ]
- ].
-
- aPrefix size > 0 ifTrue:[
- p := aPrefix , self separator
- ] ifFalse:[
- p := ''
- ].
-
- fileNames do:[:aFile | aBlock value:(p , aFile)].
- dirNames do:[:dN |
- aBlock value:(p , dN).
- (self construct:dN)
- recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN)
- ].
+ self
+ recursiveDirectoryContentsWithPrefix:aPrefix
+ filesDo:aBlock
+ directoriesDo:aBlock
"
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
@@ -2385,6 +2365,61 @@
"
!
+recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock
+ "evaluate aBlock for all files and directories found under the receiver.
+ The blocks are invoked with a relative pathname as string-argument.
+ The walk is breadth-first (first files, then directories).
+ This excludes any entries for '.' or '..'.
+ A proceedable exception is raised for non-accessible directories.
+ Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)."
+
+ |fileNames dirNames p|
+
+ "/ first collect files and dirs
+ fileNames := OrderedCollection new.
+ dirNames := OrderedCollection new.
+
+ self directoryContentsDo:[:f | |t|
+ t := self construct:f.
+ t isDirectory ifTrue:[
+ dirBlock notNil ifTrue:[
+ t isSymbolicLink ifFalse:[
+ dirNames add:f
+ ]
+ ]
+ ] ifFalse:[
+ fileBlock notNil ifTrue:[
+ fileNames add:f
+ ]
+ ]
+ ].
+
+ aPrefix size > 0 ifTrue:[
+ p := aPrefix , self separator
+ ] ifFalse:[
+ p := ''
+ ].
+
+ fileBlock notNil ifTrue:[
+ fileNames do:[:aFile | fileBlock value:(p , aFile)].
+ ].
+ dirBlock notNil ifTrue:[
+ dirNames do:[:dN |
+ dirBlock value:(p , dN).
+ (self construct:dN)
+ recursiveDirectoryContentsWithPrefix:(p , dN)
+ filesDo:fileBlock directoriesDo:dirBlock
+ ].
+ ].
+
+ "
+ '.' asFilename
+ recursiveDirectoryContentsWithPrefix:'bla'
+ filesDo:[:f | Transcript show:'file: '; showCR:f]
+ directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
+ "
+!
+
withAllDirectoriesDo:aBlock
"evaluate aBlock for myself and all (recursive) directories contained in the directory represented by the receiver.
The block is invoked with a filename-arguments.