import arcpy, os from arcpy import env folder1 = r"C:\temp\python\A" folder2 = r"C:\temp\python\B" env.workspace = folder1 for file in arcpy.ListFiles("*.csv"): fileName = file.split(".")[0] env.workspace = folder2 for file2 in arcpy.ListFiles("*.csv"): if fileName in file2: arcpy.FileCompare_management(folder1 + os.sep + file, file2, "ASCII", "CONTINUE_COMPARE", r"C:\Temp\Python" + os.sep + fileName + "_compare.txt") env.workspace = folder1
I tried to use this script and it seems that everything is working. Thank You. I have one question more why in this script "fileName = file.split(".")[0]" exist "[0]. What is changing by this?Maybe it is not smart question, but as I mentioned I just started in python.
>>> "filename.txt".split(".") ['filename', 'txt'] >>> "filename.txt".split(".")[0] 'filename'
>>> "file.name.txt".split(".") ['file', 'name', 'txt'] >>> os.path.splitext("filename.txt") ('filename', '.txt') >>> os.path.splitext("file.name.txt") ('file.name', '.txt')
import arcpy, os from arcpy import env folder1 = r"C:\temp\python\A" folder2 = r"C:\temp\python\B" env.workspace = folder1 for file in arcpy.ListFiles("*.csv"): # calculate file name # "file_name.csv" -> "file_name_A.csv" rootname = os.path.splitext(file)[0] file2name = "{0}_A.csv".format(rootname) file2path = os.path.join(folder2, file2name) # calculate compare file (output) file name compare_results = "{0}_cmp.txt".format(os.path.basename(file)) # compare the files arcpy.FileCompare_management(file, file2path, "ASCII", "CONTINUE_COMPARE", compare_results)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.