Quantcast
Viewing all articles
Browse latest Browse all 682

Deleting Folders

Please be patient with me on this, I am very new to coding.

I have seen a few examples of code to delete folders older than a certain date, but I would like to delete subfolders of subfolders. for example

c:\test\Archive\B7607\20121001_042315 Under the Archive there are many of the folders that have BXXXX and under each of those folders there are very many date_time folders.

I only need to delete the date_time folders that are odler than 30 days.

I have used the following

Code:

Set fs = CreateObject("Scripting.FileSystemObject")
ff = "C:\Test\Archive" ' your A folder
Set fo = fs.GetFolder(ff)
For Each sfo In fo.subfolders
    If DateDiff("d", sfo.datecreated, Date) > 30 Then sfo.Delete
Next
set fs = nothing

It not only deletes the date_time folders, but also the containing folder. Any help would greatly be appreciated.

Viewing all articles
Browse latest Browse all 682

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>