Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Create shapefile from .xls file with a loop -- error 000732 after 64 iterations

$
0
0
Hello there,

I am experimenting an issue with a script I wrote. I have .xls files named after a date (2020_01_01.xls) composed of two sheets (\ET$ and \P$).
In order to create shapefiles from these .xls files I made a loop over my .xls files which works fine for the 63 first iterations, but for my 64th files (2020_03_05.xls) I have an error 000732 - File doesn't exist or is not supported. However it can't be the first reason (doen't exist) because previous files doesn't bring problems. Thus I supposed it is the "not supported" reason... but I can't understand why this error happens.

I hope someone here can help me.

Koloeii

Here is a short version of my script :
#import
import sys
import os
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

#choice of model
model = "reticB1"

#define time period
byear = "2020"
eyear = "2099"

dirfiles = r"F:\Documents\journalier"
pathfiles = dirfiles+'\\'+model+'\\'
arcpy.env.workspace = pathfiles
arcpy.env.overwriteOutput = True

#list of .xls files in my directory
x=0
listFi = []
liste=os.listdir(pathfiles)
y=len(liste)
while x<y :
element=liste[x]
if element[-3:]=='xls':
listFi.append(element)
x=x+1
print (listFi)

#loop over .xls files
for Fi in listFi :
date = Fi[7:17]
in_ET=pathfiles+model+date+'.xls\\ET$'
in_P=pathfiles+model+date+'.xls\\P$'
x_coords = "coordoneeX"
y_coords = "coordoneeY"
out_ET = "ET"+date+".dbf"
out_P = "P"+date+".dbf"
if os.path.exists(pathfiles+model+'_ET'+date+'.shp'):
arcpy.Delete_management(pathfiles+model+'_ET'+date+'.shp')
if os.path.exists(pathfiles+model+'_P'+date+'.shp'):
arcpy.Delete_management(pathfiles+model+'_P'+date+'.shp')
saved_ET = pathfiles+model+'_ET'+date+'.shp'
saved_P = pathfiles+model+'_P'+date+'.shp'
spRef = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\National Grids\France\NTF France II (degrees).prj"
print (in_ET, x_coords, y_coords, out_ET, spRef)
#starting from here I tried various arcpy data management or conversion - all have error 000732 at 64th iteration
arcpy.MakeTableView_management (in_ET, "ET"+date+"view")
arcpy.MakeTableView_management (in_P, "P"+date+"view")
arcpy.TableToTable_conversion("ET"+date+"view", chemin, out_ET)
arcpy.TableToTable_conversion("P"+date+"view", chemin, out_P)
arcpy.MakeXYEventLayer_management("ET"+date+"view", x_coords, y_coords, out_ET, spRef)
arcpy.MakeXYEventLayer_management("P"+date+"view", x_coords, y_coords, out_P, spRef)
arcpy.SaveToLayerFile_management(out_ET, saved_ET)
arcpy.SaveToLayerFile_management(out_P, saved_P)

Viewing all articles
Browse latest Browse all 2485

Trending Articles