I'm working with 100+ layers on QGIS, and I am trying to determine when each layer was last created or updated. All the layers are shapefiles. Is there a way I can find the creation/update date?
-
3The last modification date on disque maybe ?– swiss_knightFeb 24, 2021 at 19:41
-
1Right out of the box the only way is to use the timestamp of the underlying operating system.– Techie_GusFeb 24, 2021 at 19:42
-
1Not unless someone documented it in the metadata– Ian Turton ♦Feb 24, 2021 at 20:02
-
And the disk timestamp doesn't even have to be right, so you might not be able to trust it.– VinceFeb 24, 2021 at 20:07
2 Answers
A bash solution for this purpose. As stated by other in comments, this recipe considers that dates on your file system/OS can be trusted
# Clean to be able to repeat the script multiple times
rm *_meta.txt
rm summary.txt
# Double loop to get basename for shp then from this basename
# get all files as your shp various files dates may differ
# Sort by date each file with same basename with `stat` command considering
# %y time of last modification, human-readable
for shp in *.shp;
do tmp=$shp;
tmp=${tmp##*/};
tmp=${tmp%.shp};
for entry in $tmp.*;
do echo $(stat -c%y "$entry")" $entry" >> $tmp"_meta.txt";
done;
done;
# Loop each file with creation date for each
# For instance, myfile_meta.txt would contains
# 2018-05-21 09:24:36.000000000 +0200 myfile_meta.cpg
# 2018-05-21 09:24:36.000000000 +0200 myfile_meta.dbf
# 2018-05-21 09:24:36.000000000 +0200 myfile_meta.prj
# 2018-05-21 09:24:36.000000000 +0200 myfile_meta.shp
# 2018-05-21 09:24:36.000000000 +0200 myfile_meta.shx
# From this file, take the last one, the more recent
# and append it to summary
for meta in *_meta.txt;
do sort $meta | tail -n 1 >> summary.txt;
done;
Use ogrinfo. However, it does not know if the editing software has been updating the last update metadata in the .dbf file. GDAL and QGIS do update it.
ogrinfo test.shp -al -so
INFO: Open of `test.shp'
using driver `ESRI Shapefile' successful.
Layer name: test
Metadata:
DBF_DATE_LAST_UPDATE=2020-11-24
See also https://gdal.org/drivers/vector/shapefile.html
Open options:
DBF_DATE_LAST_UPDATE=YYYY-MM-DD: Modification date to write in DBF header with year-month-day format. If not specified, current date is used.
and
Layer creation options:
DBF_DATE_LAST_UPDATE=YYYY-MM-DD: Modification date to write in DBF header with year-month-day format. If not specified, current date is used. Note: behavior of past GDAL releases was to write 1995-07-26
Past releases mean several years old GDAL versions.