delete all empty subfolders, vbs

Hi all,

I was able to find some code to delete all old files at certain age, but have trouble to combine with delete folders.

I am wondering if you guys have code/script i can use to delete all empty subfolders? (no age issue, just delete if empty)
thanks.

robin
robinyanwangAsked:
Who is Participating?
 
yehudahaCommented:
change this line to the path you want

ShowSubFolders FSO.GetFolder("C:\Temp")


Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("C:\Temp")
 
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        If Subfolder.Size = 0 Then
            fso.DeleteFolder Subfolder.Path
        End If
        ShowSubFolders Subfolder
    Next
End Sub

Open in new window

0
 
robinyanwangAuthor Commented:
HI, thanks for the code about folder deleting.

I have another small question about vbs...sorry, i am super fresh in vbs.

FileAge1 = DateDiff("d",file.DateLastModified, now )
FileAge2 = DateDiff("d",file.DateCreated, now )
if FileAge1  > Age and FileAge2 > age then
.
.
.
I am not sure if the syntex is currect or not? should I use 'if FileAge1  > Age and FileAge2 > age then ', or if FileAge1  > Age & FileAge2 > age then '?

thanks

robin

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
yehudahaCommented:
this is correct

if FileAge1  > Age and FileAge2 > age then
0
 
robinyanwangAuthor Commented:
thanks.

currently I am writing small vbs in notepad, and run with cscript xxx.vbs in the dos command.

do you know which tool/software should i use to code/debug these vbs?

or any book you would like to recommand to a fresh vbs person?

thanks.

robin
0
 
robinyanwangAuthor Commented:
thanks a lot!
0
 
yehudahaCommented:
no problem
thanks for the grade :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.