<?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: Selecting files from multiple folders in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176228#M13575</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;By no means is this answer going to be complete, but when specifying a file location (as in C:\DWG.....) you only need to use the double backslash after the C:\\ - so it would look like "C:\\DWG\...." or you can use single forward (/) slashes instead, which admittedly is annoying if you are doing a copy/paste of an address.&amp;nbsp; another way to reference file paths is to put an r in front of it, so like: r"C:\DWG\... ["/QUOTE]&lt;BR /&gt;Thanks for reminding me of this. I had forgotten.&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;RPI_Bryan;199036 wrote:&lt;BR /&gt;There is a free online course you can take for python in the training section.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;I did this about 2 years ago but I should probably run through it again.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 May 2012 17:33:42 GMT</pubDate>
    <dc:creator>denisedavis</dc:creator>
    <dc:date>2012-05-16T17:33:42Z</dc:date>
    <item>
      <title>Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176224#M13571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I haven't played in Python for almost two years so I'm very rusty. I'm definitely not saying I was all that good at it then. I could use some help with this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a folder, that contains many folders, and each of those folders have a file I need to grab and put it into my map. I'm going to have to do this 1000's of times so I thought a script would be nice to run. Here's what I have so far (and I got help with this too):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;

# Import arcpy module
import arcpy
import string
import os


# Local variables:
#Set workspace
arcpy.env.workspace = "C:\\DWG\\FOLDER\\FOLDER*"
Polyline = "\Polyline"
LineShp = "C:\\DWG\\FOLDER\\Shape\\"

# Process: Select
for i in arcpy.ListFiles ("*.dwg"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = i.strip('.dwgDWG')
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileout = LineShp + x + ".shp"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing:" + arcpy.env.workspace + "\\" + Polyline + "To:" + fileout
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like its running but when I go to the folder where the .shp should be, it's empty. My print statement doesn't print anything. I'm not sure I can use a wildcard for my workspace either. Thanks for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 15:19:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176224#M13571</guid>
      <dc:creator>denisedavis</dc:creator>
      <dc:date>2012-05-16T15:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176225#M13572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;By no means is this answer going to be complete, but when specifying a file location (as in C:\DWG.....) you only need to use the double backslash after the C:\\ - so it would look like "C:\\DWG\...." or you can use single forward (/) slashes instead, which admittedly is annoying if you are doing a copy/paste of an address.&amp;nbsp; another way to reference file paths is to put an r in front of it, so like: r"C:\DWG\..."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am diving into the wonderful world of python myself for the first time in 3 years, and the first time using it with arcmap.&amp;nbsp; There is a free online course you can take for python in the training section - it did a lot to get me started.&amp;nbsp; I am sure someone will be able to provide a better and more complete answer but this should at least get you started.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 16:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176225#M13572</guid>
      <dc:creator>BryanThom</dc:creator>
      <dc:date>2012-05-16T16:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176226#M13573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try posting your entire code. All I see it doing is print this line for every iteration of your loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing:" + arcpy.env.workspace + "\\" + Polyline + "To:" + fileout&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 17:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176226#M13573</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-05-16T17:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176227#M13574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try posting your entire code. All I see it doing is print this line for every iteration of your loop&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;This is all I have so far but I see what you mean. I want the shapefiles to go into the folder C:\DWG\FOLDER\Shape. Like I said, I need some help. I'm going to be a little clearer here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Open folder containing many folders&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Open each folder within the folder and get the polyline file from the dwg contained in each folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) I'd like each polyline to go straight into my map but I haven't figured that out yet so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4) make a shapefile of each polyline from each dwg that came from each folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5) I also have a query I'd like to place in the properties of each polyline from each dwg but I haven't figured that out yet either&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thank you for your time and any help you can provide.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 17:30:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176227#M13574</guid>
      <dc:creator>denisedavis</dc:creator>
      <dc:date>2012-05-16T17:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176228#M13575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;By no means is this answer going to be complete, but when specifying a file location (as in C:\DWG.....) you only need to use the double backslash after the C:\\ - so it would look like "C:\\DWG\...." or you can use single forward (/) slashes instead, which admittedly is annoying if you are doing a copy/paste of an address.&amp;nbsp; another way to reference file paths is to put an r in front of it, so like: r"C:\DWG\... ["/QUOTE]&lt;BR /&gt;Thanks for reminding me of this. I had forgotten.&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;RPI_Bryan;199036 wrote:&lt;BR /&gt;There is a free online course you can take for python in the training section.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;I did this about 2 years ago but I should probably run through it again.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 17:33:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176228#M13575</guid>
      <dc:creator>denisedavis</dc:creator>
      <dc:date>2012-05-16T17:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176229#M13576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Denise,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is some sample code that should get you started.&amp;nbsp; What you will need to do is use the 'os.walk' command to iterate through all sub-directories.&amp;nbsp; The below code starts at the directory specified with 'env.workspace' and iterates through all of its sub-directories.&amp;nbsp; It will add the polyline file of any DWG it finds.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env

env.workspace = r"C:\temp\python"


for (path, dirs, files) in os.walk(env.workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in files:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # find all DWG files in folder and all subfolders
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ".dwg" in file.lower()[-4:]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dwg_path = os.path.join(path, file) + "\Polyline"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # set the MXD
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # set the Dataframe
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd,"*")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # create a new layer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newlayer = arcpy.mapping.Layer(dwg_path)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # add the layer to the map
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, newlayer,"AUTO_ARRANGE")

del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:05:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176229#M13576</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T09:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting files from multiple folders</title>
      <link>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176230#M13577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jake! It's a great start and a whole lot of help! It's crashing after 4 iterations so I have to look at the dwg files. For some reason, I'm getting an error (no arcpy module found) when I try to run it in IDLE.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 May 2012 18:28:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-files-from-multiple-folders/m-p/176230#M13577</guid>
      <dc:creator>denisedavis</dc:creator>
      <dc:date>2012-05-16T18:28:47Z</dc:date>
    </item>
  </channel>
</rss>

