<?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 Re: Loop a function over all files in a folder with Python and GIS in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57939#M4579</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you're trying to list feature classes within a workspace (in your example: shapefiles in a directory) why not stick with arcpy instead of trying to manipulate all the string possibilities? Arcpy.ListFeatureClasses() method will give you all the shapefiles you're looking to buffer and just set the environment to the working directory. This will also help if you move to geodatabases, as windows directory structure won't work to get you your feature classes in there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Feb 2015 01:17:28 GMT</pubDate>
    <dc:creator>ToddBlanchette</dc:creator>
    <dc:date>2015-02-20T01:17:28Z</dc:date>
    <item>
      <title>Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57929#M4569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to python and I'm trying to use the python interface in ArcGIS to loop a function (buffer) over all files in a directory that I specified. I come up with the script below. However, when I run it, no errors are returned, but no files are created, nothing happens. What do I do?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; #Import arcpy
import arcpy
import os

#Naming the directory
&lt;SPAN class="s1"&gt;rootdir = "C:&lt;A href="https://community.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;SPAN class="s2"&gt;\\Users\\Fred\\Desktop\\GIS\\ModelBuilder&lt;/SPAN&gt;&lt;/A&gt; Project\\TEST"&lt;/SPAN&gt;

#allowing overwriting
arcpy.env.overwriteOutput = True

#Setting up counter
thectr = 0

#For-loop for looping function over all files in a folder
for subdirs, dirs, files in os.walk(rootdir):

&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if file == '*.shp':
# Variables
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input_layer = files
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output_layer = "C:&lt;A href="https://community.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;\\Users\\Fred\\Desktop\\GIS\\ModelBuilder&lt;/A&gt; Project\\TEST\\test" + str(thectr)
# Process: Buffer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(input_layer, output_layer, "1 Kilometers", "FULL", "ROUND", "ALL", "")
#Update counter
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thectr=thectr+1






&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also tried the script below, with the same result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# import modules
&lt;SPAN class="s1"&gt;import&lt;/SPAN&gt; arcpy&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt; glob

# folder where shapefiles are stored
&lt;SPAN class="s3"&gt;folder &lt;/SPAN&gt;&lt;SPAN class="s2"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;'C:/myfiles/'

# loop through all shapefiles
&lt;SPAN class="s1"&gt;for&lt;/SPAN&gt; shapefile &lt;SPAN class="s1"&gt;in&lt;/SPAN&gt; glob&lt;SPAN class="s2"&gt;.&lt;/SPAN&gt;glob&lt;SPAN class="s2"&gt;(&lt;/SPAN&gt; folder &lt;SPAN class="s2"&gt;+&lt;/SPAN&gt; &lt;SPAN class="s4"&gt;'*.shp'&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;):&lt;/SPAN&gt;
&lt;SPAN class="s3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;.&lt;/SPAN&gt;&lt;SPAN class="s5"&gt;Buffer_analysis&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; shapefile&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"C:/output/"&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;&lt;SPAN class="s2"&gt;+&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; shapefile&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;[-&lt;/SPAN&gt;&lt;SPAN class="s6"&gt;8&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;:-&lt;/SPAN&gt;&lt;SPAN class="s6"&gt;4&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;]&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;&lt;SPAN class="s2"&gt;+&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"buffer.shp"&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"100 Feet"&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"FULL"&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"ROUND"&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"LIST"&lt;SPAN class="s2"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s3"&gt; &lt;/SPAN&gt;"Distance"&lt;SPAN class="s2"&gt;)&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:11:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57929#M4569</guid>
      <dc:creator>FrédéricLeTourneux</dc:creator>
      <dc:date>2021-12-10T22:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57930#M4570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The output file name needs a '.shp' maybe?&lt;/P&gt;&lt;P&gt;output_layer = &lt;SPAN class="string"&gt;"C:\\Users\\Fred\\Desktop\\GIS\\ModelBuilder Project\\TEST\\test" + str(thectr) +".shp"&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 00:30:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57930#M4570</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2015-02-13T00:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57931#M4571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still not working =/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks though.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 00:42:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57931#M4571</guid>
      <dc:creator>FrédéricLeTourneux</dc:creator>
      <dc:date>2015-02-13T00:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57932#M4572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your second script (the glob script), what is the output of "print shapefile' inside the loop? Does it list anything? If so, do you notice anything out of the ordinary?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Feb 2015 01:12:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57932#M4572</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-02-13T01:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57933#M4573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're setting input_layer to files. files is a list, not a shapefile or layer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, don't think 'if file = '*.shp' will work. The * isn't working as a wildcard in this case, so most likely you're never entering the if block. This is also indicated by the fact that no error is being thrown. That code is never run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could try: if file.endswith('.shp) instead. Or import fname and use: if fname.fname('*.shp').&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd also suggest putting in some print statements so you can see what values you're getting and where in the code you are.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="comment"&gt;#For-loop for looping function over all files in a folder&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;for file &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; files:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if file.endswith('&lt;SPAN class="string"&gt;.shp')&lt;/SPAN&gt;:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('File name is: {0}'.format(file)&lt;/SPAN&gt;
&lt;SPAN class="comment"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Variables&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output_layer = &lt;SPAN class="string"&gt;"C:\\Users\\Fred\\Desktop\\GIS\\ModelBuilder Project\\TEST\\test" + str(thectr)&amp;nbsp; &lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(file, output_layer, &lt;SPAN class="string"&gt;"1 Kilometers", &lt;SPAN class="string"&gt;"FULL"&lt;/SPAN&gt;, &lt;SPAN class="string"&gt;"ROUND"&lt;/SPAN&gt;, &lt;SPAN class="string"&gt;"ALL"&lt;/SPAN&gt;, "")&amp;nbsp; &lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:11:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57933#M4573</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-10T22:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57934#M4574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This embellishment on your second (glob) script works for me. It saves the shapefile with the same name to a test folder. You can easily add a suffix, if you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import glob, os
&amp;gt;&amp;gt;&amp;gt; folder = r'C:/junk/'
&amp;gt;&amp;gt;&amp;gt; for shapefile in glob.glob( folder + '*.shp' ):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output = os.path.join(r'C:/junk/test' + os.path.basename(shapefile))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis( shapefile, output, '100 METERS')&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57934#M4574</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-10T22:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57935#M4575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A combo of Greg's and Darren's answer worked for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os, string
rootFolder = 'C:\\test'
ctr = 1
for root, dirs, files in os.walk(rootFolder):
&amp;nbsp;&amp;nbsp; for name in files:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if name.endswith(".shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # shapefile name without extension
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shpName = os.path.splitext(name)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # absolute file path
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; absFile = os.path.abspath(os.path.join(root,name))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # output file path&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output_layer = rootFolder + '\\buffer_' + shpName + '_' + str(ctr) + '.shp'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # buffer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(absFile, output_layer, "1 Kilometers", "FULL", "ROUND", "ALL", "") 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ctr = ctr + 1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:11:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57935#M4575</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-10T22:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57936#M4576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just for funzies, if you are using a simple counter like you do at the end with &lt;SPAN style="font-family: 'courier new', courier;"&gt;ctr&lt;/SPAN&gt;, you can also use &lt;SPAN style="font-family: 'courier new', courier;"&gt;+= 1&lt;/SPAN&gt; to make the code a little simpler. Just know that &lt;SPAN style="font-family: 'courier new', courier;"&gt;+=&lt;/SPAN&gt; might &lt;A href="http://stackoverflow.com/a/15376520"&gt;not always be what you want&lt;/A&gt;.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14241983156784796 jive_text_macro" jivemacro_uid="_14241983156784796"&gt;&lt;P&gt;ctr += 1&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Feb 2015 18:39:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57936#M4576</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-17T18:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57937#M4577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would try the arcpy.ListFeatureClasses() to get a list of shape file in folder.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy

# Set the workspace for ListFeatureClasses
dirpath = "C:/Users/Fred/Desktop/GIS/ModelBuilder Project/TEST"
arcpy.env.workspace = dirpath
# Use the ListFeatureClasses function to return a list of shapefiles.
featureclasses = arcpy.ListFeatureClasses()
# loop through the list of shape files
for ifc in featureclasses:
 ofc = os.path.join(dirpath,os.path.splitext(ifc)[0] + "_Buffer.shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(ifc,ofc,"1 Kilometer","FULL","ROUND","ALL","")&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:11:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57937#M4577</guid>
      <dc:creator>RichardKammer</dc:creator>
      <dc:date>2021-12-10T22:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57938#M4578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm doing the same type of thing except with an append.&amp;nbsp; I pass in the folder as an argument.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get list of shape files from specified directory&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = sys.argv[1] + "\\*.shp"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; directory = glob.glob(path)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in directory:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Append_management(filename,sys.argv[4], "NO_TEST", "SHAPE.AREA \"SHAPE.AREA\" false false true 0 Double 0 0 ,First,#;SHAPE.LEN \"SHAPE.LEN\" false false true 0 Double 0 0 ,First,#", "")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(traceback.format_exc())&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; error = "Y"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Feb 2015 18:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57938#M4578</guid>
      <dc:creator>Hernando_CountyProperty_Apprai</dc:creator>
      <dc:date>2015-02-19T18:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a function over all files in a folder with Python and GIS</title>
      <link>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57939#M4579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you're trying to list feature classes within a workspace (in your example: shapefiles in a directory) why not stick with arcpy instead of trying to manipulate all the string possibilities? Arcpy.ListFeatureClasses() method will give you all the shapefiles you're looking to buffer and just set the environment to the working directory. This will also help if you move to geodatabases, as windows directory structure won't work to get you your feature classes in there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Feb 2015 01:17:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-a-function-over-all-files-in-a-folder-with/m-p/57939#M4579</guid>
      <dc:creator>ToddBlanchette</dc:creator>
      <dc:date>2015-02-20T01:17:28Z</dc:date>
    </item>
  </channel>
</rss>

