Henry Colgate and Marc,
Jumping on the ride here, for the last few weeks Ive been messing around with this script to get this correct function and Im getting some layer files being mapped whilst others not.
What want to do:
a) Map out the layers files that are in use in a mxd (shps should be dealt with with the glob, but doesnt include tiffs)
b) Get the size of the collection of shps (i.e. test.shp consists of test.dbf, test.proj etc and I want to get the size of this bunch) - problem
c) Total size calculator of how much data is in the mxd - cant figure best way of doing this as b is blocking me
I found a really nice library called humanize to help the size conversion.
import arcpy, os, humanize, glob
def write_log(text,file):
f = open(file,'a')
f.write("{}\n".format(text))
return
output = r'X:\ds\sizemxd.txt'
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)
write_log("This report summarizes the names of all map documents and data frames within " + mxd.filePath + "\n",output)
write_log("Date: " + str(datetime.datetime.today().strftime("%d %B, %Y")) + "\n",output)
for d in df:
write_log("Data Frame: " + d.name, output)
layers = arcpy.mapping.ListLayers(mxd, "", d)
for lyr in layers:
try:
if lyr.supports("dataSource"):
lname = lyr.name
print "lname: " + lname
datasource = lyr.dataSource
wspath = lyr.workspacePath
if datasource.endswith('.shp'):
stringwspath = str(wspath).replace("\\", '/')
path = stringwspath + "/"
print "Path: " + path
for shp in glob.glob(os.path.join(path,'{0}.*').format(lname)):
shp = str(shp).replace("\\", '/')
print "stripped " + stripshp
try:
size = os.stat(shp).st_size
print "size of shp " + stripshp + " is " + humanize.naturalsize(size)
except:
print "unable to access size of " + shp
else:
pass
else:
pass
except:
print "Unable to analyse size for " + lname.encode('utf-8')
The output is:
Path: C:/Users/ds/Desktop/ |
stripped C:/Users/ds/Desktop/E458_search.cpg |
size of shp C:/Users/ds/Desktop/E458_search.cpg is 9 Bytes |
stripped C:/Users/ds/Desktop/E458_search.dbf |
size of shp C:/Users/ds/Desktop/E458_search.dbf is 391 Bytes |
stripped C:/Users/ds/Desktop/E458_search.sbn |
size of shp C:/Users/ds/Desktop/E458_search.sbn is 252 Bytes |
stripped C:/Users/ds/Desktop/E458_search.sbx |
size of shp C:/Users/ds/Desktop/E458_search.sbx is 124 Bytes |
stripped C:/Users/ds/Desktop/E458_search.shp |
size of shp C:/Users/ds/Desktop/E458_search.shp is 2.3 kB |
stripped C:/Users/ds/Desktop/E458_search.shp.NB-055.12412.16264.sr.lock |
size of shp C:/Users/ds/Desktop/E458_search.shp.NB-055.12412.16264.sr.lock is 0 Bytes |
stripped C:/Users/ds/Desktop/E458_search.shx |
size of shp C:/Users/ds/Desktop/E458_search.shx is 204 Bytes |
lname: E458_HSR_LITHO_29092017_acQ |
lname: E458ThinSections_17082017 |
Path: C:/shps/ |
stripped C:/shps/E458ThinSections_17082017.CPG |
size of shp C:/shps/E458ThinSections_17082017.CPG is 5 Bytes |
stripped C:/shps/E458ThinSections_17082017.dbf |
size of shp C:/shps/E458ThinSections_17082017.dbf is 36.7 kB |
stripped C:/shps/E458ThinSections_17082017.prj |
size of shp C:/shps/E458ThinSections_17082017.prj is 409 Bytes |
stripped C:/shps/E458ThinSections_17082017.sbn |
size of shp C:/shps/E458ThinSections_17082017.sbn is 260 Bytes |
stripped C:/shps/E458ThinSections_17082017.sbx |
size of shp C:/shps/E458ThinSections_17082017.sbx is 124 Bytes |
stripped C:/shps/E458ThinSections_17082017.shp |
size of shp C:/shps/E458ThinSections_17082017.shp is 492 Bytes |
stripped C:/shps/E458ThinSections_17082017.shp.NB-055.12412.16264.sr.lock |
size of shp C:/shps/E458ThinSections_17082017.shp.NB-055.12412.16264.sr.lock is 0 Bytes |
stripped C:/shps/E458ThinSections_17082017.shp.xml |
size of shp C:/shps/E458ThinSections_17082017.shp.xml is 789 Bytes |
stripped C:/shps/E458ThinSections_17082017.shx |
size of shp C:/shps/E458ThinSections_17082017.shx is 212 Bytes |
lname: PBT_FieldObservationPoints_24072017 |
Path: G:/08/E458/Data/Geology/Observation Points/ |
lname: PBT_FieldDescriptions_24072017 |
Path: G:/08/E458/Data/Geology/IntegratedGeol/PBT Maps/ |
so for the last two files PBT_FieldObservationPoints_24072017 and PBT_FieldDescriptions_24072017, I can see in the folder that there do exist shp files but for some reason it doesnt register them to get their size checked.
Would anyone be able to help with this?
Thanks in advance