I see 2 issues with your procedure:
SubFolders
is always aFolders
collection, sosf
will never beNothing
and your code will never enter theElse
branch (thus never processing any files). Change your condition fromNot subf Is Nothing
to
fldr.SubFolders.Count > 0
GetExtenstionName()
only returns a single extension, soGetExtensionName("file.tar.gz")
will producegz
, nottar.gz
, so even if your code entered theElse
branch (which it doesn't) it still wouldn't delete any files. You need something like this to extract double extensions from a file name:ext = fso.GetExtensionName(fso.GetBaseName(fname)) & "." _ & fso.GetExtensionName(fname)
BTW, you don't need
CStr()
here, sinceGetExtensionName()
already returns a string.
As for your question regarding return()
: in what respect to you mean "equivalent"? If you want the procedure/function to return to the caller you can do that via Exit Sub
and Exit Function
respectively. If you want to return a value to the caller, you can do that by assigning the value to the function name:
Function Foo()
Foo = "bar"
End Function
Note that the latter works only for functions, not procedures. Also, the assignment can take place anywhere in the function body, it doesn't have to be at the end.
On a more general note, I wouldn't use StrComp()
for string comparisons unless you actually want to make use of the 3-state comparison it does (less/equal/greater). Better (as in "better readable") would be a simple comparison like this:
If LCase(ext) = "tar.gz" Then