I made a script that allows me to make folders based on the name of the month and by number of weeks. I also have a file in dbf format with names of people, and each record in this file becomes folders within each week per month.

The script works very well so far, however, the only problem in the result, it only runs until the month of SEP, and within each folder per month, in week 4, only the names of the people in this last folder are saved.

What I need really is to save all the names of the people by week until the last month 'DEC'

This is the script.

import arcpy
import os
env.workspace = r'F:\VICTOR_QB\Asignacion de Cargas'
ruta_salida = r'F:\VICTOR_QB\Asignacion de Cargas\Levantamiento'

#Name folder
Months = ['ENE','FEB','MAR','ABR','MAY','JUN','JUL','AGO','SEP','OCT','NOV','DIC']
Weeks = ['Week1','Week2','Week3','Week4']

#CoWorkers  file .dbf
Tabla_origen = r'F:\VICTOR_QB\Asignacion de Cargas\Lista de Brigadistas\BRIGADISTA.dbf'

#Search CoWorkes's names
CoWorkers = [row[0] for row in arcpy.da.SearchCursor(Tabla_origen,Field)]
Unicos_Briga = set(CoWorkers)

#Make folders with months, weeks and coworkers
for M  in Months:
    meses = arcpy.CreateFolder_management(ruta_salida,M)
    for W in Weeks:
     semanas = arcpy.CreateFolder_management(meses,os.path.join(W))
    for B in Unicos_Briga:
     carpetas_brigadistas = arcpy.CreateFolder_management(semanas,os.path.join(B))

print 'Done'
  • 3
    Try indenting the two lines, for B and carpetas_ , so they execute for each week. – klewis Jun 25 '18 at 19:15
  • In fact python's os module has a function for that. Specifically os.makedirs. – fatih_dur Jun 26 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.