I have two folders containing 1800 files each. I need to merge or combine them based on their names, e.g. file
MOD10A2.A2017177.h24v05.006.2017187224801.tif in folder A should combine/merge with the file
MYD10A2.A2017177.h24v05.006.2017191190921.tif in folder B and file
MOD10A2.A2017188.h24v05.006.2017183445431.tif in folder A should combine/merge with the file
MYD10A2.A2017188.h24v05.006.2017134567541.tif in folder B and so on. And I want the resulted images in folder C.
The following code actually executes successfully but it doesn't write or save the resulted images or files in folder C.
Here is the code (courtesy BERA)
import os, arcpy from collections import defaultdict as dd baseFolder = r'D:\data' # containing two sub-folders d = dd(list) for root, folders, files in os.walk(baseFolder): for file in files: d[file.split('.')].append(os.path.join(root, file)) for partname, pathlist in d.items(): if len(pathlist)==2: fullPaths = [os.path.join(root, f) for f in pathlist] if all(os.path.isfile(p) and p.endswith('.tif') for p in fullPaths): arcpy.MosaicToNewRaster_management(input_rasters=';'.join(fullPaths), output_location='D\combined_data', raster_dataset_name_with_extension=partname+'.tif', number_of_bands=1)