# Sorted array of files

**URL:** <https://forum.mikrotik.com/t/sorted-array-of-files/151870>\
**Category:** Scripting\
**Created:** [September 14, 2021, 1:33pm UTC](https://forum.mikrotik.com/t/sorted-array-of-files/151870 "2021-09-14T13:33:31Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Izdatyi](https://forum.mikrotik.com/letter_avatar/izdatyi/32/6_449c533f586939b6e5f246632a46421f.png) [@Izdatyi](https://forum.mikrotik.com/u/Izdatyi)\
**Post date:** [September 14, 2021, 1:33pm UTC](https://forum.mikrotik.com/t/sorted-array-of-files/151870/1 "2021-09-14T13:33:31Z")

</div>

Hi  
It is possible to get sorted array (by name or creation-time) with **/file find**?  
I need to delete recent n files  
 ![Снимок экрана 2021-09-14 162542.png](https://data-discourse.cdn.mikrotik.com/original/3X/6/c/6c189f71df74fa0c66f334fa609ef3f41d55a202.png)

```plaintext
[admin@MikroTik7-Test] > /file print detail where name~"MikroTik7-Test_.+\\.backup\$" 
 0 name="MikroTik7-Test_2021-09-14_132825.backup" type="backup" size=72.9KiB creation-time=sep/14/2021 13:28:25 
 1 name="MikroTik7-Test_2021-09-14_132104.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:21:04 
15 name="MikroTik7-Test_2021-09-14_142900.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 14:29:00 
 3 name="MikroTik7-Test_2021-09-14_132205.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:22:05 
 4 name="MikroTik7-Test_2021-09-14_132340.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:23:40 
 5 name="MikroTik7-Test_2021-09-14_132455.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:24:55 
 7 name="MikroTik7-Test_2021-09-14_133044.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:30:44 
 8 name="MikroTik7-Test_2021-09-14_115638.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 11:56:38 
16 name="MikroTik7-Test_2021-09-14_142715.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 14:27:15

# Part of my script
:local bkFilesArr [/file find name~"MikroTik7-Test_.+\\.backup\$"]
:local bkFilesLen [:len $bkFilesArr]
:log info "bak [6.2] backups: $bkFilesLen"
:local i 0
:foreach file in=$bkFilesArr do={
    :log info ("bak [6.3.$i] $file " . [/file get $file name])
    set $i ($i + 1)
}

```

---

_[View the full topic](https://forum.mikrotik.com/t/sorted-array-of-files/151870)._
