Here is what i have so far, it deletes the files in the folder, but i cannot get it to delete the actual folder. Any help would be greatly appreciated:


Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

strSourceFolder = "c:\test"
intDel = 0

dtOld = DateAdd("d", -intDel, Date)

Set objFolders = objFSO.GetFolder(strSourceFolder)

ForEach filIn objFolders.Files
   IfDateDiff("d", fil.datelastaccessed, dtOld) >= intDelThen
      objFSO.DeleteFile fil.Path
Set objFSO = Nothing

Answer Summary:
0 Comments   [ - ] Hide Comments


Please log in to comment

Community Chosen Answer





Answered 05/01/2013 by: SMal.tmcc
Red Belt

  • This syntax works like a charm: forfiles -p "C:\temp" -s -c "cmd /c del /Q /S @path" /d -1
    • and this actually deleted the folder and no the files: FORFILES /P C:\K1000Backup /S /D 0 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"
Please log in to comment
Answer this question or Comment on this question for clarity



doesn't seem to work get this error with this syntax: 

ForFiles /P C:backups  /D -4 “CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE”



Answered 05/01/2013 by: areiner
Fourth Degree Black Belt

  • does not look like there is a " in front of CMD and at the end looks like more of a O circumflex
Please log in to comment

I've used this in Powershell before.

$Now = Get-Date

#Enter number of days to check here.

$Days = "2"

#Path to File.

$TargetFile = "c:\temp"

$LastWrite = $Now.AddDays(-$Days)

$Files = Get-Childitem $TargetFile -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}

foreach ($File in $Files)


    if ($File -ne $NULL)


     write-host "Deleting File $File" -ForegroundColor "DarkRed"

     Remove-Item $File.FullName | out-null




     Write-Host "No more files to delete!" -foregroundcolor "Blue"


Answered 05/01/2013 by: dugullett
Red Belt

Please log in to comment

If you want to delete the folder, why bother faffing with deleting the files first? Just use the DeleteFolder method! :-)



Answered 05/02/2013 by: VBScab
Red Belt

  • Well I am running an FTP back up of my k1000 box to a network share which is backed up nightly by Avamar. The k1000 generates a folder that the back ups are in with the same name scheme every night with the date. So i want to delete the old one so we only have the most recent one backed up via Avamar.

    that may make no sense, it's early here, haven't had coffee.
Please log in to comment
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja