hi phv,
thankU 4 replying...
I thought i nailed this but guess i was wrong
The code below prints out the folders which match a certain criteria how do i change it so that it deletes the ones that don't match that criteria
Private Sub Command1_Click()
Set fsoDelete = CreateObject("Scripting.FileSystemObject")
Dim mypath, mydir, myfile, counter, i
counter = 1
' Display the names in C:\ that represent directories.
mypath = "C:\image\" ' Set the path.
mydir = Dir(mypath, vbDirectory) ' Retrieve the first entry.
strFolder = mydir Like "[a-z][a-z]####"
Do While mydir <> "" ' Start the loop.
strFolder = mydir Like "[a-z][a-z]####"
counter = counter + 1 '' counts # of directories passed
' Ignore the current directory and the encompassing directory.
If mydir <> "." And mydir <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(mypath & mydir) And vbDirectory) = vbDirectory Then
If strFolder = True Then
Debug.Print mydir ' Display entry only if it
Else
' Delete All folders that don't match aa####
fsoDelete.DeleteFolder mypath & mydir, True
Debug.Print mydir
End If
myfile = Dir(mypath & mydir & "\", vbNormal)
Do While myfile <> ""
' Debug.Print "---- " & myfile
myfile = Dir
Loop
End If ' it represents a directory.
End If
mydir = Dir(mypath, vbDirectory) ' Retrieve the first entry.
For i = 1 To counter
mydir = Dir ' Get next entry.
Next
Loop