-2

I have the following code and for some reason I can not go back and check for next FC name. This code work great before I added if "os.path.exists()" and if, all files exist in both folders. Please point out what is the problem. Thanks!

import arcpy
from arcpy import env
import os
arcpy.env.overwriteOutput = True
Match_FC=arcpy.GetParameterAsText(0)
Matched=Match_FC[-10:-1]
arcpy.AddMessage
env.workspace =arcpy.GetParameterAsText(1)
output=arcpy.GetParameterAsText(2)
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
 if os.path.exists(fc==Matched):
    if fc[-10:-1]==Matched:
      arcpy.MakeFeatureLayer_management(fc, output,'','','')
 pass
Koush
  • 1

2 Answers2

1

os.path.exists() takes path on the file system and check if it exists, and you feed it with bool value.

For example: os.path.exists('/path/to/my/file') returns True if file exists.

Edit:

I suppose you would like to do this:

for fc in fcList:
    if fc == Matched:
        # do sth if matched
    else:
        # do sth if not matched. If you don't need else branch just delete it, without pass
sashadereh
  • 223
  • 1
  • 15
0

The code says os.path.exists(fc==Matched) - notice the ==. The expression fc==Matched can be either True or False, so you're checking whether True or False exist as paths.

They probably don't, which is why you never get inside the if.

zmbq
  • 38,013
  • 14
  • 101
  • 171