'Purge backup older than 14 days python

I have a python code which is connected to jenkins now I have to purge those jenkins_backup which are older than 14 days. I tried this and I am getting output while testing with local system but it is not working in jfrog artifactory

def walk_dir(backup_id, bucket, bucket_prefix):
    artlocation = ArtifactoryBackup(f'{bucket}/{bucket_prefix}')
    past_time = date.today() - timedelta(days=14)
    for path in Path(artlocation).iterdir():
        timestamp = date.fromtimestamp(path.stat().st_mtime)
        if path.is_file() and past_time > timestamp:
            print(f'Delete file --> {path}')
            # path.unlink() # Delete files
        if path.is_dir():
            walk_dir(path)
        try:
            # path.rmdir() # Delete empty folders
            pass
        except (FileNotFoundError, WindowsError):
            pass


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source