Filename.st
changeset 13793 3f1c660956ce
parent 13781 c691e88e1900
child 13795 f8ee373fcdcf
--- a/Filename.st	Mon Oct 10 13:11:45 2011 +0200
+++ b/Filename.st	Tue Oct 11 13:22:47 2011 +0200
@@ -2855,6 +2855,56 @@
     "
 !
 
+new_recursiveRemoveAll
+    "Remove all of my subfiles/subdirectories.
+     Raise an error if not successful.
+     This one walks down the directory hierarchy, not using any OS
+     command to do the remove."
+
+    |files toRemove fileToRemove|
+
+    self isDirectory ifFalse:[^ self].
+    files := self directoryContentsAsFilenames.
+    files isEmpty ifTrue:[^ self].
+
+    toRemove := OrderedCollection new.
+    toRemove addAll:files.
+    [ toRemove notEmpty ] whileTrue:[
+        fileToRemove := toRemove removeLast.
+        Error handle:[:ex |
+            |children|
+
+            fileToRemove isDirectory ifTrue:[
+                children := fileToRemove directoryContentsAsFilenames.
+                children isEmpty ifTrue:[
+                    fileToRemove remove
+                ] ifFalse:[
+                    toRemove add:fileToRemove.
+                    toRemove addAll:children.
+                ].
+            ] ifFalse:[
+                ex reject 
+            ].
+        ] do:[
+            Transcript showCR:('remove: ', fileToRemove pathName).
+            fileToRemove remove.
+        ].
+    ].
+
+    "
+     'foo' asFilename makeDirectory.
+     'foo/bar' asFilename writeStream close.
+     'foo' asFilename remove
+    "
+    "
+     'foo' asFilename makeDirectory.
+     'foo/bar' asFilename writeStream close.
+     'foo' asFilename recursiveRemove
+    "
+
+    "Created: / 11-10-2011 / 10:28:09 / cg"
+!
+
 recursiveCopyTo:destination
     "if I represent a regular file, copy it.
      Otherwise, copy the directory and recursively
@@ -3043,7 +3093,8 @@
      This one walks down the directory hierarchy, not using any OS
      command to do the remove."
 
-    self recursiveRemoveAll.
+    self new_recursiveRemoveAll.
+    "/ self recursiveRemoveAll.
     self remove
 
     "
@@ -3058,7 +3109,7 @@
     "
 
     "Created: / 25-02-1998 / 19:50:40 / cg"
-    "Modified: / 25-01-2011 / 16:42:24 / cg"
+    "Modified: / 11-10-2011 / 10:29:20 / cg"
 !
 
 remove
@@ -3069,15 +3120,17 @@
     |linkInfo osName ok|
 
     osName := self osNameForFile.
-    linkInfo := self linkInfo.
-    (linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[
-        ok := OperatingSystem removeDirectory:osName
-    ] ifFalse:[
-        ok := OperatingSystem removeFile:osName
-    ].
-    ok ifFalse:[
-        self exists ifTrue:[
-            self removeError:self
+    (ok := OperatingSystem removeFile:osName) ifFalse:[
+        linkInfo := self linkInfo.
+        (linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[
+            ok := OperatingSystem removeDirectory:osName
+"/        ] ifFalse:[
+"/            ok := OperatingSystem removeFile:osName
+        ].
+        ok ifFalse:[
+            self exists ifTrue:[
+                self removeError:self
+            ]
         ]
     ].
 
@@ -3093,8 +3146,8 @@
      'foo' asFilename recursiveRemove.   
     "
 
-    "Modified: / 20.11.1997 / 17:40:22 / stefan"
-    "Modified: / 5.5.1999 / 13:41:12 / cg"
+    "Modified: / 20-11-1997 / 17:40:22 / stefan"
+    "Modified: / 11-10-2011 / 10:20:01 / cg"
 !
 
 removeDirectory
@@ -5845,11 +5898,11 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.369 2011-10-07 16:39:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.370 2011-10-11 11:22:47 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.369 2011-10-07 16:39:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.370 2011-10-11 11:22:47 cg Exp $'
 ! !
 
 Filename initialize!