I want semi-automate copying and categorizing DCIM files from my iPhone to my computer, keeping "related" camera images together and separate from screenshots, downloaded jpeg's, gifs, mpeg's, png's, etc.
On my iPhone I have a bunch of downloaded images (from Pinterest, Tumblr, etc). I also have bunch of related jpg/mp4 pictures taken with the iPhone camera that are in related pairs, one following the other in filename order. Apparently the iPhone camera records both a jpeg image and a multi-frame mp4 movie for each picture taken. Downloaded images are just single jpegs, gifs, mp4's etc.
I would like the script to reside on the local computer and run manually after the iPhone is mounted.
The iPhone image paths are:'mtp://Scottc's iPhone/Internal Storage/DCIM/291APPLE', 'mtp://Scottc's iPhone/Internal Storage/DCIM/292APPLE', 'mtp://Scottc's iPhone/Internal Storage/DCIM/293APPLE', etc.
I don't have control over the subdirectory names (such as 291APPLE, 292APPLE, 293APPLE, etc. but they always start with a (seemingly random) 3-digit number and always end in "APPLE". There can be one or ten. It just depends on iOS and the number of files. The subdirectories are read-only but the files themselves are read-write so can be deleted later.
So, I need to work with all the files recursively up to 'mtp://Scottc's iPhone/Internal Storage/DCIM/'.
The directory listing in each subfolder on the iPhone looks something like this:
*image001.jpg* <-- downloaded
*image002.jpg* <-- downloaded
*image003.jpg* <-- camera image a
*image004.mp4* <-- camera image b
*image005.jpg* <-- downloaded
*image006.jpg* <-- downloaded
*image007.jpg* <-- downloaded
*image008.jpg* <-- downloaded
*image009.jpg* <-- camera image a
*image010.mp4* <-- camera image b
*image011.jpg* <-- downloaded
So files 003 and 004 are related, and files 009 and 010 are related. All the files in Scottc's iPhone/DCIM/* have unique names.
I would like to copy only the related images to directory A and the remaining images (downloads, which can be of any type jpg, gif, mp4, etc.) to Directory B.
Can anyone help with the Powershell logic and code that would make this possible? I really have no idea how to accomplish this. Maybe there is a better way or a utility someone already wrote? If so, I have been unable to find it and dealing with hundreds of images at a time is really tedious. This seems like the perfect application for Powershell.
I think I need to loop through the files, identify the first *.mp4 file, put the filename in to a variable, copy the *.mp4 file to Directory A, then subtract the value 1 from the variable to match the preceding related *.jpg filename in alphabetical order and copy that to Directory A.
Rinse and Repeat.
Then copy the remaining unrelated files (of any type) to Directory B.
So, in the end I have the following directory structure:
On the iPhone: (leave the original files as is) Directory A image003.jpg <-- camera image a image004.mp4 <-- camera image b image009.jpg <-- camera image a image010.mp4 <-- camera image b Directory B image001.jpg <-- downloaded image002.jpg <-- downloaded image005.jpg <-- downloaded image006.jpg <-- downloaded image007.jpg <-- downloaded image008.jpg <-- downloaded image011.jpg <-- downloaded
Finally, ask the user if they want to delete the iPhone originals (I can handle that part, I think) but not the iPhone directories (the permissions issue mentioned above...iOS takes care of the directory structure).
One gotcha I think is that a downloaded movie ending in *.mp4 will be matched with an unrelated *.jpg file which was downloaded just previously. Unless someone has an elegant way to handle that. I can live with that minor limitation. I've noticed that the related jpg/mp4 files have the same hh:ss timestamp if that helps. Downloaded images/movies/gifs never match time-wise. Maybe matching the timestamps is easier? No idea how to accomplish that either.
Where I am really confused is the handling of the filename variable(s), the mathematical -1 logic when working with filenames and how to handle the remaining filenames (in an array, or through iteration?). The copy, move, name match, etc. I think I can work out through trial and error--but feel free to elaborate. What some can do on the fly takes me hours, often ending in failure and frustration :-(
Can anyone help? My Powershell skills are up to about Chapter 3-ish so I'm really struggling.