TransWikia.com

Way I can find out when a shapefile was created or last updated

Geographic Information Systems Asked by user178004 on June 23, 2021

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?

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;

Answered by ThomasG77 on June 23, 2021

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.

Answered by user30184 on June 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP