|
-
Oct 2nd, 2000, 10:19 AM
#1
I'm using the following code that I found on this site to remove ONLY empty directories. Does anyone have a better routine than this one? Sometimes the procedure is finished within a second, sometimes it takes 15+ seconds, sometimes it never finishes (gets in an infinite loop).
Thanks in advance,
Dave
-
Oct 2nd, 2000, 10:20 AM
#2
Sorry, here's the code:
Public Sub remove_folders(root_dir As String, Optional recursive As Long)
On Error Resume Next
Dim idx As Long
Dim upper_limit As Long
Dim sub_folder() As String
If IsMissing(recursive) = True Then
recursive = 0
End If
ReDim sub_folder(idx)
sub_folder(idx) = Dir(root_dir, vbDirectory Or vbNormal Or vbHidden Or vbReadOnly Or vbSystem)
Do While sub_folder(idx) <> vbNullString
idx = idx + 1
ReDim Preserve sub_folder(idx)
sub_folder(idx) = Dir
Loop
If idx <= 2 Then
Call RmDir(root_dir)
'Only deletes if directory is empty.
DoEvents
Else
upper_limit = UBound(sub_folder) ' - 1
For idx = 0 To upper_limit Step 1
If GetAttr(root_dir & sub_folder(idx)) = vbDirectory _
And sub_folder(idx) <> "." _
And sub_folder(idx) <> ".." Then
Call remove_folders(root_dir & sub_folder(idx) & "\", recursive + 1)
End If
Next idx
End If
Erase sub_folder
End Sub
-
Oct 4th, 2000, 09:21 AM
#3
Don't worry about it, I've coded my own routine that works great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|