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.
Jake used the string .split() method to extract the base name of the file (without the extension). A very cool thing about Python is you can try this yourself interactively at the prompt to figure out how it works:
>>> "filename.txt".split(".")
['filename', 'txt']
>>> "filename.txt".split(".")[0]
'filename'
An alternative way to do this is to use the os.splitext() method, which will give you correct results even if the file name contains a ".", for example: "file.name.txt":
>>> "file.name.txt".split(".")
['file', 'name', 'txt']
>>> os.path.splitext("filename.txt")
('filename', '.txt')
>>> os.path.splitext("file.name.txt")
('file.name', '.txt')
Here's my version of the script, which takes more advantage of the os module, and loops more the way you were asking. Unlike Jake's script, however, any deviations from your file naming setup will cause the script to fail. Jakes method is more forgiving. (My version isn't really better, just different.)Another difference: I'm writing the results to folder1 instead of TEMP.
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)