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
  EndIf
Next
Set objFSO = Nothing
wscript.quit


Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

1

http://www.mojobudgie.com/a-simple-batch-script-to-delete-folders-older-than-x/

 

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

Answers

0

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”

 

pause

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
0

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

     }

     else

     {

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

     }

     }
Answered 05/01/2013 by: dugullett
Red Belt

Please log in to comment
0

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

http://msdn.microsoft.com/en-us/library/ca0at0xh%28v=vs.84%29.aspx

 

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
Answer this question or Comment on this question for clarity