Hello All,
Background: We have a "diagnostics" folder on our network that is used to store logs exported from our flagship application.
The problem I'm trying to solve is to remove any files/folders older than 30 days from the "diagnostics" folder.
The following code is being used to perform this:
- name: Find all files older than 30 days in diagnostics folder
win_find:
paths: "{{ unc_path }}"
file_type: directory
age: 30d
#recurse: yes
register: FilesOver30
- name: Delete all files/folders older than 30 days from diagnostics folder
win_file:
path: "{{ unc_path }}"
state: absent
with_items: "{{ FilesOver30.files }}"
The issue I'm having is, if there are no files newer than 30 days in the "diagnostics" folder, it actually nukes the diagnostics folder itself, which is not the intended result.
Need to be able to have it remove any files/folders older than 30 days from this folder witout nuking the entire thing.
Thanks in advance for the feedback!