I have a task in Task Scheduler (Windows Server 2016 Standard) that runs a simple .bat file calling python.exe and my python file. One of the first things my .py file does is use
arcpy.da.Walk to search through a file geodatabase for certain feature classes, appending their full paths to a list.
This function (and the entire script) runs fine either in VS Code (debug or not), and by running my .bat directly from File Explorer. It logs a populated list and moves on. However, when I run this .bat file as a task in Task Scheduler, and check the log file, the list of feature classes is empty. It doesn't seem to be recognizing the location Walk is trying to search, so the directory is empty. There is no exception thrown or anything, so I'm unaware of any further debugging I can do.
I've tried the following:
- Checked permissions
- Set the task to run with the highest privileges
- Set the task to run whether or not the user is logged in
- Tried changing the "Start In" argument to my project folder where the FGDB is, and even tried setting it to the FGDB itself
Might anyone know why
arcpy.da.Walk wouldn't work via Task Scheduler, but otherwise runs fine?
# Data Sources sde_conn = r'F:\BatchJobs\DB_Connections\ecch-gis@[email protected]' parcel_history = os.path.join(sde_conn, "bd_TaxParcelHistory") parcels_gdb = r'S:\GIS\DATA Production\Data\SanGIS\Parcel\Parcels\Parcels.gdb' buffer_1k = r'F:\BatchJobs\ParcelHistory\ParcelHistory.gdb\TaxParcels_Buffer1000' lm_parcel_path = '' def main(argv=None): # Start the process logger.info("==== RDW_DataProcessing.py started ====") arcpy.env.overwriteOutput = True arcpy.env.workspace = parcels_gdb ## Get a list of all TaxParcels_<date> FCs in Parcels.gdb. These ## are the ones clipped to the SDE 2x3Boundary logger.info("Finding all TaxParcels_<date> Feature Classes in FGDB") fcs_to_compare =  try: parcels_walk = arcpy.da.Walk(parcels_gdb, datatype='FeatureClass') for dirpath, dirnames, filenames in parcels_walk: for filename in filenames: logger.info(filename) if filename.find("TaxParcels_") > -1: filepath = os.path.join(dirpath, filename) fcs_to_compare.append(filepath) logger.info(fcs_to_compare) lm_parcel_path = fcs_to_compare[-2] except Exception as e: logger.error(str(e.args))