-1

When i was importing my photos from my ipad to my hard disk i mistakenly imported them with the creation date of that day.

So now the true date for each photo is the modified date of it. I basically use this command to Setfile -d "$(GetFileInfo -m _FILE_PATH_)" _FILE_PATH_ to set the creation date of my photo to its modified date. But i was wondering if there is a way to put this command line in a python script where i can batch select multiple photos to preform this action.

Also, since if I open any photo the system will change its modified date, the only way that i can guess which date some photos belong to is by sorting them by name to see which date the photos before and after it belong to.

Any ideas on how I can write a script that deduces the real date of photos which have dates larger than a specific date based on the photos before and after it?

For example, you see in the screenshot that there is a photo from May 8 between two photos from October 5, so clearly it should be taken on October 5 as well. But unfortunately sometimes the modified date of the photos before and after a photo are also wrong so I think the program has to look for the smallest date before and after the photo to deduce the real date. enter image description here

UPDATE

I wrote this code on the python and it works fine for single files when I drag and drop them into the terminal to give the program the path. Im wondering if there is a way to do this with multiple files.

from subprocess import call
import os

path = input("enter filepath: ")
info = '"$(GetFileInfo -m '+ path + ')" '
command = 'Setfile -d ' + info + path
print('Setfile -d ' + info + path)
call(command, shell=True)
  • tried https://stackoverflow.com/q/56008797/10197418 ? – FObersteiner Oct 16 '20 at 08:20
  • In its current form this is definitely too broad. Show us the code you have so far, with a [mre] of the problem you are currently unable to solve yourself. – tripleee Oct 16 '20 at 09:26
  • @tripleee hi there, i update the question with my code. This only works for single files. I wanna know how I can do multiple at once. – user13273663 Oct 16 '20 at 09:39

1 Answers1

1

Not requiring interactive input is probably a crucial improvement so that you can run this on a large number of files at the same time. The way to do that in Python is with sys.argv.

Also, rather than subprocess.call, use subprocess.check_call (or subprocess.check_output to get the output) so that you can avoid invoking a shell, and check that the subprocess completed successfully. (There will be a traceback if not; if you want something more user-friendly, wrap it in try/except. Probably look for existing questions before posting another question asking for help with that.)

from subprocess import check_output, check_call
from sys import argv

for path in argv[1:]:
    date = check_output(['GetFileInfo', '-m', path])
    check_call(['Setfile', '-d', date, path])

Use it like

python3 script.py file1.png /path/to/file2.png ../elsewhere/file3.png ...

(Relative paths are resolved starting from your current working directory; no path resolves to the current directory.)

tripleee
  • 175,061
  • 34
  • 275
  • 318