<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Failed to loop through the files in a folder in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1075604#M42909</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am making a looping code for Intersect_analysis of multiple files in a folder, but I ended up with having only one outcome..&amp;nbsp;&lt;/P&gt;&lt;P&gt;''''&lt;/P&gt;&lt;P&gt;### folder containing facilities&lt;BR /&gt;in_folder_2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES"&lt;/P&gt;&lt;P&gt;shp_file_list_2 = [ ]&lt;BR /&gt;path_list2 = [ ]&lt;BR /&gt;intersectInput_list = [ ]&lt;/P&gt;&lt;P&gt;for shp_file2 in os.listdir(in_folder_2):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if shp_file2.endswith(".shp"):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; intersectInput = os.path.join(in_folder_2, shp_file2)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; intersectInput_list.append(intersectInput)&lt;BR /&gt;&lt;BR /&gt;intersectInput_list&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;['D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\N3A_A0010000.shp', 'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\TBGIS_TRDAR_RELM_prj.shp', 'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\UPIS_SHP_ZON216.shp']&lt;/PRE&gt;&lt;P&gt;interFeature = r"D:\WORK\PROJECT\COVID_19_2\Created_Data\PED_FLOW\eoul_flow_time_ymd_20200401.shp"&lt;/P&gt;&lt;P&gt;out_folder2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES_INTERS"&lt;/P&gt;&lt;P&gt;for intersectInput in intersectInput_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; inFeatures = [intersectInput, interFeature]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name = shp_file2.strip(".shp")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; clusterTolerance = 10&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;intersectOutput = os.path.join(out_folder2, name)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; arcpy.Intersect_analysis(inFeatures, intersectOutput, "", clusterTolerance, "point")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below is my output. Please help me, since I will increase the files in the folder much more than the current 3.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES_INTERS\\UPIS_SHP_ZON216.shx'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Jul 2021 23:16:59 GMT</pubDate>
    <dc:creator>JinseoYoon</dc:creator>
    <dc:date>2021-07-07T23:16:59Z</dc:date>
    <item>
      <title>Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1075604#M42909</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am making a looping code for Intersect_analysis of multiple files in a folder, but I ended up with having only one outcome..&amp;nbsp;&lt;/P&gt;&lt;P&gt;''''&lt;/P&gt;&lt;P&gt;### folder containing facilities&lt;BR /&gt;in_folder_2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES"&lt;/P&gt;&lt;P&gt;shp_file_list_2 = [ ]&lt;BR /&gt;path_list2 = [ ]&lt;BR /&gt;intersectInput_list = [ ]&lt;/P&gt;&lt;P&gt;for shp_file2 in os.listdir(in_folder_2):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if shp_file2.endswith(".shp"):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; intersectInput = os.path.join(in_folder_2, shp_file2)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; intersectInput_list.append(intersectInput)&lt;BR /&gt;&lt;BR /&gt;intersectInput_list&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;['D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\N3A_A0010000.shp', 'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\TBGIS_TRDAR_RELM_prj.shp', 'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES\\UPIS_SHP_ZON216.shp']&lt;/PRE&gt;&lt;P&gt;interFeature = r"D:\WORK\PROJECT\COVID_19_2\Created_Data\PED_FLOW\eoul_flow_time_ymd_20200401.shp"&lt;/P&gt;&lt;P&gt;out_folder2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES_INTERS"&lt;/P&gt;&lt;P&gt;for intersectInput in intersectInput_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; inFeatures = [intersectInput, interFeature]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; name = shp_file2.strip(".shp")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; clusterTolerance = 10&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;intersectOutput = os.path.join(out_folder2, name)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; arcpy.Intersect_analysis(inFeatures, intersectOutput, "", clusterTolerance, "point")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below is my output. Please help me, since I will increase the files in the folder much more than the current 3.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'D:\\WORK\\PROJECT\\COVID_19_2\\GIS\\CREATED_DATA\\FACILITIES_INTERS\\UPIS_SHP_ZON216.shx'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 23:16:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1075604#M42909</guid>
      <dc:creator>JinseoYoon</dc:creator>
      <dc:date>2021-07-07T23:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1075608#M42910</link>
      <description>&lt;P&gt;I can't see where shapefile2 is referenced for the second for loop, and where outfolder2 is set, why are you stripping .shp from the filename, is the .shx extension intended?&amp;nbsp; Also the code isn't formatted so I cant see the indents, making it a mess to try and read.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 11:21:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1075608#M42910</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-05T11:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1076551#M43023</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, the shape_file2 is referenced in the the upper part of the code (for shp_file2 in os.listdir(in_folder_2): ...)&lt;/P&gt;&lt;P&gt;Second, I stripped the ".shp" to use the same name of the file for the output files in a different folder.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Third, I omitted to copy the part of the code indicating the location of the output file folder, now I added it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please advise?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 23:21:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1076551#M43023</guid>
      <dc:creator>JinseoYoon</dc:creator>
      <dc:date>2021-07-07T23:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1076558#M43025</link>
      <description>&lt;P&gt;Even then you're outputting a file&amp;nbsp;&lt;SPAN&gt;intersectOutput&amp;nbsp;&lt;/SPAN&gt;without an extension? That would only work if Outfolder2 was a GDB. That seems to be why only an shx file is being created.&lt;/P&gt;&lt;P&gt;I don't really know what's going on with ShapeFile2 unless you present your code with the proper formatting/indentation. i.e. throw us a bone.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 23:33:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1076558#M43025</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-07T23:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1077713#M43176</link>
      <description>&lt;P&gt;Hi David,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response. The problem that I have was the failing of the loop. I input the three files but only one outcome has been created. The shx. shp. extension is not an issue. I could use both types.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attaching the code file, if you can advise me again - on why my loop could not go through all of the files in the list - it would be very much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 08:38:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1077713#M43176</guid>
      <dc:creator>JinseoYoon</dc:creator>
      <dc:date>2021-07-12T08:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1077733#M43179</link>
      <description>&lt;P&gt;you must surely get an error that shapefile2 is not referenced? what errors are you getting?&amp;nbsp;&lt;/P&gt;&lt;P&gt;intersectInput_list is also on a line without any context.&lt;/P&gt;&lt;P&gt;I'd also use&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfeatureclasses.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfeatureclasses.htm&lt;/A&gt;&amp;nbsp;when dealing with shapefiles in a folder.&lt;/P&gt;&lt;P&gt;I've quickly (very quickly) adjusted the code, but it is not ideal and not my finest work.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;### folder containing facilities 
in_folder_2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES"

shp_file_list_2 = [ ]
path_list2 = [ ]
intersectInput_list = [ ]

for shp_file2 in os.listdir(in_folder_2):
    if shp_file2.endswith(".shp"):
        intersectInput = os.path.join(in_folder_2, shp_file2)
        #append a list of [name, path] for shapefile2
        intersectInput_list.append([shp_file2, intersectInput])
    
##intersectInput_list 

interFeature = r"D:\WORK\PROJECT\COVID_19_2\Created_Data\PED_FLOW\eoul_flow_time_ymd_20200401.shp"

out_folder2 = r"D:\WORK\PROJECT\COVID_19_2\GIS\CREATED_DATA\FACILITIES_INTERS"

for intersectInput in intersectInput_list:
    inFeatures = [intersectInput[1], interFeature]
    name = intersectInput[0]
    clusterTolerance = 10 
    intersectOutput = os.path.join(out_folder2, name)
    arcpy.Intersect_analysis(inFeatures, intersectOutput, "", clusterTolerance, "point")&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 12 Jul 2021 09:50:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1077733#M43179</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-12T09:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to loop through the files in a folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1080125#M43425</link>
      <description>&lt;P&gt;I am sorry for the delayed response. It works well!! Thank you very much!!! Honestly I do not understand the reason clearly, but I will compare your and my code and figure out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much again!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 04:27:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-loop-through-the-files-in-a-folder/m-p/1080125#M43425</guid>
      <dc:creator>JinseoYoon</dc:creator>
      <dc:date>2021-07-19T04:27:57Z</dc:date>
    </item>
  </channel>
</rss>

