mercredi 22 février 2017

if/else statement - moving files and continuing if file does not exist

I am using python to move DBF files from one folder to multiple folders. These come to me from an S3 bucket and I unzip and move. Sometimes there will be a missing DBF. If that happens I am trying to code so that if the file is not there the script moves to the next file. I figure this would be an if/else statement but I am having trouble with the else part.

import arcpy, os
from arcpy import env

env.workspace = "E:\staging\DT_TABLES"

######Move Clackamas Pro41005.dbf######
in_data =  "Pro41005.dbf"
out_data = "D:/DATATRACE/OREGON/OR_TRI COUNTY/Pro41005.dbf"
data_type = ""

if in_data == "Pro41005.dbf":
        arcpy.Delete_management(out_data)
        arcpy.Copy_management(in_data, out_data, data_type)
        print 'Clackamas Moved'
else :

######Move Multnomah Pro41051.dbf######

    in_data =  "Pro41051.dbf"
    out_data = "D:/DATATRACE/OREGON/OR_TRI COUNTY/Pro41051.dbf"
    data_type = ""

    arcpy.Delete_management(out_data)

    arcpy.Copy_management(in_data, out_data, data_type)

print 'Multnomah Moved'

In other words, if Pro41005.dbf was not in the zipped file I like the script to continue to Pro41051.dbf This is two of eight files that I am moving. In time there will be about 20 files.

Aucun commentaire:

Enregistrer un commentaire