I wonder how to get size of disk space that a specific vector dataset occupies on a disk. I didn't find any ogr2ogr util or OGR Python method that can return a list of files that belongs to given dataset. I could use ogr2ogr util or CopyDataSource OGR method to copy the dataset to new empty directory using the same driver and analyze the directory then but this method do not preserve original features (and file size) or even does not allow dataset creation for some of OGR formats. Another way is to make a list of possible file extensions that may belongs to given vector format and try to test if the file exists... Any other ideas?
The problem is that shapefiles have only 3 mandatory files and ogr or other Python modules recognize only those (+ eventually the .prj file)
Many applications as ArcGIS or QGIS add other specific files, not recognized by the modules.
You need to use an artifice as in Retrieving size of shapefile in ArcPy? but the use of a list of extensions as in the script presented is too limited in scope (only for ArcGis).
A proposition, for example
import glob,os shapefiles = [file for file in glob.glob("*.shp")] # name of the first shapefile (without extension) name = os.path.splitext(shapefiles) print name 'test' # test.shp # search string search = '*'+ name + '*.*' for file in glob.glob(search): print file, os.path.getsize(file) test.dbf 176 test.prj 497 test.qpj 783 test.shp 268 test.shx 108 # total size in bytes print sum([os.path.getsize(file) for file in glob.glob(search)]) 1832
With a filter
extensions = [".shp", ".shx",".dbf"] # without .qpg and .prj for file in glob.glob(search): if os.path.splitext(file) in extensions: print file, os.path.getsize(file) test.dbf 176 test.shp 268 test.shx 108 print sum([os.path.getsize(file) for file in glob.glob(search) if os.path.splitext(file) in extensions]) 552