I have been using ArcGIS 10.3.1.
I have a list of tables in an enterprise geodatabase with date and time in the table name. Every day one table is created, as an outcome of some geoprocessing tasks with the date and time in the table’s name when the table is created.
Naming format of the tables are FHRT_YYYYmmdd_HHMMSS
Like
- FHRT_20190808_071015 (this table is created on 08 August 2019 at 07:10:15)
- FHRT_20190807_071218 (this table is created on 07 August 2019 at 07:12:18)
- FHRT_20190806_071119
- FHRT_20190805_071913
- FHRT_20190804_071418
- FHRT_20190803_071014
- FHRT_20190802_070815
etc.
I want to create a python script that will keep the latest 3 tables (in this example FHRT_20190808_071015, FHRT_20190807_071218 and FHRT_20190806_071119) and delete the rest with similar name format. The geodatabase may have other tables with other name format (cadastre, property etc.), I do not want to touch those.
Being new in Python I do not know how I would create the script that will specify the dates.
I mean how will I instruct the script to keep the 3 tables that have the latest dates and delete the older tables?
What module do i need to import and what would be the statement?
Thank you in advance.
Regards,
Hafiz