Creating folders help (python beginner)

797
6
02-23-2012 07:18 AM
chukwuemekaobilor
New Contributor
I am trying to create folders and each folder will have a name from a field in my grid layer.
My grid has 500 tiles and I need to create 500 folders.  The naming convention is like 001A1, 001A2,
001A3, 001B1, 001B2, 001B3, 001C1, 001C2, 001C3, 002A1...................

My code starts like this
import sys, string, os, arcgisscripting, traceback
gp = arcgisscripting.create()
env.workspace = "C:\Backup Files\Backup Files\GISPROJECTS\Python_Practice"


# Set local variables
output_folder_path= "C:\Backup Files\Backup Files\GISPROJECTS\Python_Practice"out_name = "folder1"
output_folder_name = foldername

# Execute CreateFolder
Tags (2)
0 Kudos
6 Replies
DarrenWiens2
MVP Honored Contributor
import os
os.mkdir("H:/newfolder") # makes folder "newfolder" on H:
0 Kudos
chukwuemekaobilor
New Contributor
thanks, How can i have it create 500 folders with different names
0 Kudos
DarrenWiens2
MVP Honored Contributor
Use a Search Cursor to loop through the grid cells (I assume your grid is a grid of polygons...?) to get the cell's value. Then, inside the loop, incorporate the cell value into a path string, then use that string inside os.mkdir().
0 Kudos
DanPatterson_Retired
MVP Emeritus
this line will fail
env.workspace = "C:\Backup Files\Backup Files\GISPROJECTS\Python_Practice"
either use double backslashes, a single foreslash or append an r to the beginning of the path
0 Kudos
chukwuemekaobilor
New Contributor
thanks all.  I will start trying it out and see how it work.  definetly this is new to me but I will surely get it right.  thanks again
0 Kudos
chukwuemekaobilor
New Contributor
Use a Search Cursor to loop through the grid cells (I assume your grid is a grid of polygons...?) to get the cell's value. Then, inside the loop, incorporate the cell value into a path string, then use that string inside os.mkdir().


yes it is a polygon
0 Kudos