locked
Batch job to delete files older than 2 days RRS feed

  • Question

  • Hi , I  created a script to delete files and folder that are older than 2 days. I was able to run it but when there are no files the job fails. How to ignore/ by pass when there are no files, My scripts fails if no files exists at that location. 

    @echo off
    :: set folder path
    net use Y: \\networkDrive\QA
    :: set min age of files and folders to delete
    set max_days=2
    :: remove sub directories from %dump_path%
    forfiles.exe /p Y:\ErrorFolder/d -%max_days% /c "cmd /c IF @isdir == TRUE rd /S /Q @path"
    net use Y: /delete /Yes

    • Moved by Dave PatrickMVP Monday, January 4, 2021 10:48 PM looking for forum
    Monday, January 4, 2021 10:34 PM

Answers

All replies