How to get a sorted list of the last n files?

Good Afternoon All,

I am looking for a way to get a list of files in a directory sorted by name.

At the moment I am using the command module to run ls on the remote system.

Is it possible with the find module to sort the results by the path?

This is how I am doing it at the moment https://gist.github.com/greglangford/b9da158684f607687c3c867887f2d835

Kind Regards

Good Afternoon All,

I am looking for a way to get a list of files in a directory sorted by name.

At the moment I am using the command module to run ls on the remote system.

Is it possible with the find module to sort the results by the path?

Not with find directly, but you can do when using the result.

This is how I am doing it at the moment
https://gist.github.com/greglangford/b9da158684f607687c3c867887f2d835

tasks:
   - find: path=/tmp
     register: files

   - debug: msg="{{ item.path }}"
     with_items: "{{ (files.files | sort(attribute='path'))[-3:] }}"

That's perfect just what I needed. Thank you so much.

Kind regards