|
POST
|
I tried this, but the repeats were still skipped: for root, dirnames, filenames in os.walk(im): #iterate directory
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get 'Date Taken' from JPG
ds = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
nt = time.strftime("%Y-%m-%d",ds)
newname = fname[:-4].replace(' ','_').replace('(','').replace(')','').replace('.','') + '_' + nt + ".jpg"
print(newname) prints: 7400010_2018-04-25.jpg
7400015_2018-04-25.jpg
7400016_2018-04-25.jpg
7400017_2018-04-25.jpg
...
... View more
07-23-2019
01:58 PM
|
0
|
2
|
3193
|
|
POST
|
Randy, that works nice, but is it possible to put the whole directory into a list?
... View more
07-23-2019
01:53 PM
|
0
|
0
|
3193
|
|
POST
|
Joshua, that appended JPG to the end of the date and skipped the repeats:
... View more
07-23-2019
01:22 PM
|
0
|
0
|
3193
|
|
POST
|
Hello, I have a lot of JPEGs in a Windows directory. In most cases these JPEGs do not have similar filenames. On the other hand, there are some repeats: Using exifread, I'm appending the 'date taken' to the end of the seven digit number of the filenames. This script gets me close, but it's not exactly doing what I want. It skips the files with similar names (e.g. 7400010 (2), 7400010b). Also, after running the script I'm having trouble avoiding the '.' of the file extension. Ideally, I'd like every filename to have this structure: 7400010_2018-04-25. And as far as the files with similar names goes, how do I preserve the (2) and the b? """
Loops through folder and adds the 'Date Taken' from JPG
"""
import arcpy, sys
import exifread
from exifread import exif
import os
##import time
from datetime import datetime
im = r"\\path\to\pics2\CH74"
for root, dirnames, filenames in os.walk(im): #iterate directory
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get 'Date Taken' from JPG
ds = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
nt = time.strftime("%Y-%m-%d",ds)
newname = fname[0:8] + "_" + nt + ".jpg"
image.close()
os.rename(os.path.join(root,fname), os.path.join(root,newname)) Here's how the filenames look after running this script:
... View more
07-23-2019
12:23 PM
|
0
|
8
|
3348
|
|
POST
|
Weng, It is Collector for ArcGIS, actually. Version 18.0.3. I should've mentioned that.
... View more
06-20-2019
07:07 AM
|
0
|
0
|
1205
|
|
POST
|
I can't find a way to change the green symbols in the map? There doesn't seem to be a way to do it in the CSS. On the other hand, I was able to change the number to light blue in the panel at least. Version: 2.9.0 JS API: 3.27 Here's the app: https://webapp.willcountyillinois.com/gisweb/2019_July4th/index.html
... View more
06-18-2019
12:35 PM
|
0
|
1
|
1246
|
|
POST
|
Hello, how do I lose what appears to be a subtitle ('1035243.583' in the popup box)? The number itself is from the attribute field called "Easting". I only want to see 'Post Number: 2610010'. In the web map Easting doesn't appear in the popup:
... View more
06-13-2019
12:12 PM
|
0
|
2
|
1293
|
|
POST
|
Thanks to GeoNet, here's the work around I eventually came up with seeing that using Python to update a raster field isn't supported. In the end I didn't use a raster field at all. I had a text field with a unique ID that matched the file name of JPGs in a directory. I used a script that updated another text field named 'Photo' with the full name of the JPG. Then I used arcpy.EnableAttachments_management(), which created a related table that can store rasters. Finally, I used arcpy.AddAttachments_management(), which populated the related table. Working with attachments was also helpful. '''the purpose of this script is to update the 'Photo' field in the fc
with the file path of the same name.
'''
import arcpy, os
ws = r'path\to\Projects\DOT_SignInventory\pics'
jpgs = {} # empty dictionary
for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
jpgs[fname[:-4]] = os.path.join(dirName,fname)
for jpg in jpgs:
print(jpg)
fc = r'path\to\Projects\DOT_SignInventory\Data2.gdb\WCDOT_Signs'
fields = ['OID@', 'Post_Number', 'Photo']
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
try:
row[2] = jpgs[row[1]]
cursor.updateRow(row)
except KeyError:
print("No photo for: {}".format(row[1]))
del cursor
... View more
04-24-2019
08:06 AM
|
0
|
0
|
3301
|
|
POST
|
Hello, The intention of this script is to update the 'Photo' field of a feature class table with the full path of a JPG based on the 'Post_Number' field. The problem is only the first seven digits of the JPG matches the unique ID in the 'Post_Number' field. The rest of the file name is a date. I've placed a string index number variable in a for loop that gets the JPG by the first seven digits. A dictionary is then built off the existing paths without the date. The cursor is then supposed to update the 'Photo' field. The script runs without error but the Photo field isn't updated?? I'm thinking the 'var' variable is in the wrong place. '''Python 3.6.6. The purpose of this script is to update the 'Photo' field in the fc
with the full path of a JPG.
'''
import arcpy, os
ws = r'path\to\Projects\DOT_SignInventory\pics'
jpgs = {} # empty dictionary
for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
var = fname[:7] # get first seven digits of file name
jpgs[var[:-4]] = os.path.join(dirName,var)
fc = r'path\to\Projects\DOT_SignInventory\Data2.gdb\WCDOT_Signs'
fields = ['OID@', 'Post_Number', 'Photo'] # fields of FC
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
try:
row[2] = jpgs[row[1]]
cursor.updateRow(row)
except KeyError:
print("No photo for: {}".format(row[1]))
del cursor
Here's how the JPG looks in the directory: Here's how I want the Photo field to be updated. Right now it's empty. Both fields are text fields.
... View more
04-23-2019
01:32 PM
|
0
|
1
|
1251
|
|
POST
|
Thanks, that's it. Here's how I put it in: for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
var = fname[:7]
jpgs[var[:-4]] = os.path.join(dirName,var) The script runs without error, but now I have to figure out why the Photo field isn't being populated.
... View more
04-23-2019
09:33 AM
|
0
|
0
|
1358
|
|
POST
|
I have a working script that updates the 'photo' field with a file path to a JPG based on the 'post_number' field. In other words, the script searches the directory for JPGs which it puts into a dictionary with it's file path. It then uses a cursor to update the photo field with a path to the JPG. import arcpy, os, re
ws = r'path\to\Projects\DOT_SignInventory'
jpgs = {} # empty dictionary
for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
jpgs[fname[:-4]] = os.path.join(dirName,fname)
fc = r'path\to\Projects\DOT_SignInventory\Data.gdb\WCDOT_Signs'
editws = os.path.dirname(fc)
fields = ['OID@', 'Post_Number', 'Photo']
# Start an edit session. Must provide the workspace.
edit = arcpy.da.Editor(editws)
# Edit session is started without an undo/redo stack for versioned data
# (for second argument, use False for unversioned data)
edit.startEditing(False, True)
# Start an edit operation
edit.startOperation()
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
try:
row[2] = jpgs[row[1]]
cursor.updateRow(row)
except KeyError:
print("No photo for: {}".format(row[1]))
del cursor
# Stop the edit operation
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
It works fine now because the 'Post_Number' field is the same as the JPG: My problem is that the JPG will soon have a date concatenated to look like this, for example: 0110100_20180607. So, my question is how can I change the code so it uses only those first seven digits to populate the Photo field? They are both text fields.
... View more
04-22-2019
02:12 PM
|
0
|
3
|
1457
|
|
POST
|
Thanks a lot! I did put the image.close() line in at one point. But, I didn't dedent it as you have. I also never dedented os.rename().
... View more
04-16-2019
02:25 PM
|
0
|
0
|
5544
|
|
POST
|
Tried both options, and also tried '%Y%m%d'. Still throwing the PermissionError. Here's what I have: import arcpy, sys
import exifread
from exifread import exif
import os
import time
from datetime import datetime
im = "path\to\DOT_SignInventory"
for root, dirnames, filenames in os.walk(im): #iterate directory
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get 'Date Taken' from JPG
ds = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
nt = time.strftime("%Y-%m-%d",ds)
newname = fname[0:7] + "_" + nt + ".jpg"
os.rename(os.path.join(root,fname), newname)
... View more
04-16-2019
01:17 PM
|
0
|
2
|
5544
|
|
POST
|
Randy, I tried: newname = fname[0:7] + "_" + nt + ".jpg"
os.rename(os.path.join(root,fname), os.path.join(root,newname)) Even within the with loop it's throwing a Permission Error: PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'path\\to\\DOT_SignInventory\\CH01\\0100010.JPG' ->
'path\\to\\DOT_SignInventory\\CH01\\0100010_04/27/2018.jpg'
... View more
04-16-2019
12:32 PM
|
0
|
4
|
5544
|
|
POST
|
I need some help putting the date in the filenames. Here's the working code I have so far. import arcpy, sys
import exifread
from exifread import exif
import os
import time
from datetime import datetime
im = r"path\to\DOT_SignInventory"
for root, dirnames, filenames in os.walk(im): #iterate directory
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get 'Date Taken' from JPG
ds = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
nt = time.strftime("%m/%d/%Y",ds)#variable with 'Date Taken'
print("Photo:{} Date Taken:{}".format(fname, "_" + nt)) I've tried these couple things after the print statement, but no cigar: new_file = fname + nt + ".jpg" f = open(fname.format(nt), "w")
f.write(fname + nt)
f.close
... View more
04-16-2019
09:05 AM
|
0
|
7
|
5888
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM | |
| 1 | 11-12-2025 08:37 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|