Having several digital cameras is fun: you can have different photography experiences.
However, organizing pictures is far less interesting, especially if you do not have a consistent process (like naming convention) for archiving. After several years, I end up with hundred thousand pictures sitting in messy huge folders:
Nikon_Pictures
Backup_SDCard01
100_0302
DCIM_From_Old_Phone
100CANON
Backup-Photo
etc…
The most tricky part, is that I have so many duplicate pictures everywhere due to inconsistent archiving during years. It is so messy that I never dare to manually clean them up.
Naturally, the knowledge of programming came to my rescue. This time, it is Python.
Solution
Long story short, I am using Python 3, and a lib exifread for extracting exif data from pictures.
You can install exifread by running below command
1
pip install exifread
Then, here comes the ~100 line of code:
sourceRootFolder and targetRootFolder specify the source and target folders (sorry, I am too lazy to parametric them)
It extracts camera model and create a folder with same name, such as NIKON D40. It also works with smart phones, like Nokia 925.
It extracts picture date, then create sub-folder with YYYY-MM format.
Move the picture to that sub-folder. If there is already a file with same file name in the target folder, move this file to a backup folder. If the backup folder also have the same file, do nothing.
firstAttemptFilePath = targetFolder + "\\" + filename print(firstAttemptFilePath) if os.path.isfile(firstAttemptFilePath): #check if we can move to the backup attemptToBackupFilePath = targetFolderBackup + "\\" + filename if os.path.isfile(attemptToBackupFilePath): #have the same file in the backup folder #do nothing print ("------[skip]:" + sourceFilePath) else: #move to backup ifnot os.path.isdir(targetFolderBackup): os.makedirs(targetFolderBackup) shutil.move(sourceFilePath, attemptToBackupFilePath) print (">>>>>>[backup]:" + sourceFilePath)