Answered by:
Batch job to delete files older than 2 days

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
-
I'd try asking for help over here.
winapi-general - Microsoft Q&A
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Dave PatrickMVP Tuesday, January 5, 2021 2:31 PM
- Marked as answer by Dave PatrickMVP Tuesday, January 5, 2021 11:50 PM
Monday, January 4, 2021 10:48 PM -
Hello,
if it's a batch file on a server, you could ask here: https://docs.microsoft.com/en-us/answers/topics/windows-server-management.html
- Proposed as answer by Dave PatrickMVP Tuesday, January 5, 2021 2:31 PM
- Marked as answer by Dave PatrickMVP Tuesday, January 5, 2021 11:50 PM
Tuesday, January 5, 2021 6:50 AM
All replies
-
I'd try asking for help over here.
winapi-general - Microsoft Q&A
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Dave PatrickMVP Tuesday, January 5, 2021 2:31 PM
- Marked as answer by Dave PatrickMVP Tuesday, January 5, 2021 11:50 PM
Monday, January 4, 2021 10:48 PM -
Hello,
if it's a batch file on a server, you could ask here: https://docs.microsoft.com/en-us/answers/topics/windows-server-management.html
- Proposed as answer by Dave PatrickMVP Tuesday, January 5, 2021 2:31 PM
- Marked as answer by Dave PatrickMVP Tuesday, January 5, 2021 11:50 PM
Tuesday, January 5, 2021 6:50 AM