/build/static/layout/Breadcrumb_cap_w.png

Need help with script on deleting Folders older than X days

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



0 Comments   [ + ] Show comments

Answers (4)

Answer Summary:
Posted by: SMal.tmcc 11 years ago
Red Belt
1

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

 


Comments:
  • This syntax works like a charm: forfiles -p "C:\temp" -s -c "cmd /c del /Q /S @path" /d -1 - areiner 11 years ago
    • 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" - areiner 11 years ago
Posted by: areiner 11 years ago
4th Degree Black Belt
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


Comments:
  • does not look like there is a " in front of CMD and at the end looks like more of a O circumflex - SMal.tmcc 11 years ago
Posted by: dugullett 11 years ago
Red Belt
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"

     }

     }
Posted by: anonymous_9363 11 years ago
Red Belt
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

 


Comments:
  • 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. - areiner 11 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ