-
I'm working on an app which in some cases creates subfolders below "App.Path" (got that part working fine) and in some cases I want to go through and delete all such subfolders (each subfolder is named with a specific pattern). The second part is where I'm stuck. I would like to use the FSO; I've used it a little bit and would like to use it more. I envision the pseudocode for this thing as something like the following:
Code:
'pseudocode:
For Each Subfolder In (App.Path)
If Subfolder.Name Like "MyPattern" Then
fso.DeleteFolder Subfolder.Name
End If
Next
Can someone help and substitute the pseudocode with the proper VB syntax? I would be eternally grateful ...
-
<?>
Code:
'this will kill all sub folders in C:\My Documents
Option Explicit
Sub ShowFolderList(folderspec)
Dim fs, f, f1, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 In sf
s = f1.Name
fs.Deletefolder (folderspec & "\" & s)
s = s & vbCrLf
Next
End Sub
Private Sub Image1_Click()
Call ShowFolderList("C:\my documents")
End Sub
-
Thanks Wayne, I appreciate the help. If you don't mind, here's a follow-up question. I know that in VBScript, all variables are variant, but in straight VB, what would you DIM these variables as? I know that "f" and "f1" would have to be "Folder", but how about "sf"?
-