import arcpy
from arcpy import da
import os
attachTable = 'C:\users\user\Test2\pictures.gdb\pictures__ATTACH' # Table in GDB holding attatchments
origTable = 'C:\Users\user\Test2\pictures.gdb\pictures' # Layer in GDB holding features to which attatchments belong
nameField = 'Name' # Field where you want to save the photos
fileLocation = 'C:\Users\user\pictures\pics' # folder where you want to save the photos
# creates a cursor to search through the attachment tables; specify yu only wish to search those three fields
attachCursor = arcpy.da.SearchCursor(attachTable, ['DATA', 'ATT_NAME', 'REL_GLOBALID'])
# Begin searching the table and storing the actual images, movies, etc.
for attRow in attachCursor:
binaryRep = attRow[0]
filename = attRow[1]
relID = attRow[2]
# creates a cursor to sort the features; essentially to find a match fro the relID above
originCursor = arcpy.da.SearchCursor(origTable, ['GLOBALID', nameField])
for origRow in originCursor:
origID = origRow[0]
origName = origRow[1]
if origID == relID:
break
# Saves a file in the specified location tht contains the name chosen by the user for the attachment
open(fileLocation + os.sep + origName + ".jpg", 'wb').write(binaryRep.tobytes())
# deletes search cursor
del originCursor
ERROR
Traceback (most recent call last):
File "C:/Users/mpretorius/Desktop/att.py", line 28, in <module>
open(fileLocation + os.sep + origName + ".jpg", 'wb').write(binaryRep.tobytes())
IOError: [Errno 2] No such file or directory: u'C:\\Users\\user\\pictures\\pics\\HGC-2.jpg'
Can't seem to figure out what is wrong in this script. Any help appreciated!