Hi.
To do the task that you describe, you need to create a pythonscript that finds all the lyrx files in the directory, then create a featurelayer and get the number of features of that layer. There are several options for getting the layerfiles, using the modules os, glob or pathlib (from Python 3.4). This example uses the glob-module
import glob
folder = r'C:\Maps\LayerFiles\*.lyrx' # your folder with lyrx
elements = glob.glob(folder) #get the files
Then you need to iterate each of the files, create a featurelayer and get the number of features:
for element in elements:
featurelayer = "FeatureLayer"
arcpy.MakeFeatureLayer_management(in_features=element, out_layer=featurelayer) # create featurelayer from element
c = arcpy.GetCount_management(featurelayer) # get count of features
arcpy.Delete_management(in_data=featurelayer) # delete featurelayer
For sending the e-mail, you need to use the smtp-library, and call the sendEmail method each time the count is greater than 0. You can see the use of the smtplib here:
import smtplib
def sendEmail(layername):
sender = 'from@fromdomain.com'
receivers = ['to@todomain.com']
message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: Issues found in {0}
Records where found in the {0} query. Please investigate""".format(layername)
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Good luck 🙂