import arcpy from os import path as p ### less typing, replaces os.path with p test = r'C:\TestData\PathTest_Table.dbf' # change this to point to your table newpath = r'c:\\Users\Desktop\Pictures' rows = arcpy.UpdateCursor(test) for row in rows: row.Test_1 = p.join(newpath,p.basename(row.Context_ph)) # Make sure you have the correct field names after "row." rows.updateRow(row) del row, rows print 'done'
import arcgisscripting import os gp = arcgisscripting.create(9.3) table = r'C:\TestData\Path_to_your_table' newpath = r'c:\\Users\Desktop\Pictures' rows = gp.UpdateCursor(table) for row in rows: row.Picture2 = os.path.join(newpath,os.path.basename(row.Picture)) rows.updateRow(row) row = rows.Next() del row del rows print 'done'
That has got me in the right direction, but it is not completely helping me out. For example: In the field called "Picture" there are a bunch of directories of where pictures are located. My goal is to get all of the directories to change to the same directory and keep same name for that image. c:\\Users\Desktop\1\Picture\IMG_001.jpg > c:\\Users\Desktop\Pictures\IMG_001.jpgc:\\Users\Desktop\2\Picture\IMG_002.jpg > c:\\Users\Desktop\Pictures\IMG_002.jpgc:\\Users\Desktop\3\Picture\IMG_003.jpg > c:\\Users\Desktop\Pictures\IMG_003.jpgI have got replace to work, but it is not the complete function I am looking for. I am looking to replace everything 12 spaces from the right with c:\\Users\Desktop\Pictures I have not found anything to help me with this yet.
import arcpy from os import path as p ### less typing, replaces os.path with p test = r'C:\TestData\PathTest_Table.dbf' newpath = r'c:\\Users\Desktop\Pictures' rows = arcpy.UpdateCursor(test) for row in rows: row.Path_2 = p.join(newpath,p.basename(row.Path_1)) rows.updateRow(row) del row, rows print 'done'
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.