Automating find/replace file in same path procedure

Discussion in 'Mac Programming' started by macstatic, Nov 10, 2015.

  1. macstatic, Nov 10, 2015
    Last edited: Nov 10, 2015

    macstatic macrumors 6502a

    Joined:
    Oct 21, 2005
    #1
    I've got all my photos organized in folders/subfolders and do multiple backups on external drives. Somehow I managed to mess up the creation dates of many photos, but fortunately I have the original (unmodified) photos on one of the backup drives :)

    Using Finder's search criteria I've created a Smart-search to display all photos with wrong dates, but with many photos to replace I would like to have the process partly automated (partly because I want to preview each photo to ensure they're all replaced with the correct ones).

    So... (given that I have one (external) drive with the wrongly dated files (displayed in a Finder window thanks to my Smart-search) and a separate drive with the exact same file/folder structure containing the same files but with correct dates)... is there a way I can have Automator or a script of some sort do the following:

    - analyzing the path of the first (wrong date) file, locate the same file (correct date) on the backup drive
    - add "_err date" to the wrongly dated file, then copy the correctly dated file into the same folder
    - allow me to preview (quick look) both image files before comitting
    - repeat the procedure with the next wrongly dated file

    As I said both the source and backup drives are external and have the exact same file/folder structure, so the path would be the same except for the drive name of course, i.e.:
    starting with the source drive (wrong creation dates on many (but not all) files...

    /Volumes/Photos/
    /2012/
    /2012-01/
    /Greece vacation/
    /Sunday family dinner/
    /Grandpa visiting/​
    /2012-02/
    /Danny says hello/
    /Pete's wedding/
    ....and the backup drive (correct creation dates):

    /Volumes/Photos backup/
    /2012/
    /2012-01/
    /Greece vacation/
    /Sunday family dinner/
    /Grandpa visiting/​
    /2012-02/
    /Danny says hello/
    /Pete's wedding/​


    I'm on OSX 10.9.5.
     
  2. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #2
    You don't need to copy any files if the only problem is creation dates. You can change the creation timestamp using "touch".

    I would suggest having a look at how to write a shell script. Useful skill to have and plenty of example on the net. You will probably need things like nested for loops and/or use find. You can use stat to get the creation time of a file and touch to update the creation time of a file.

    Backup things before making any changes.

    You may also be able to get the same effect with the correct rsync invocation now I think of it.
     
  3. macstatic, Nov 10, 2015
    Last edited: Nov 15, 2015

    macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #3
    It's a little complicated because there are so many date tags in photos which makes it confusing where the problem lies. It appears that the EXIF info is instact on most of the photos though I'm not 100% sure if that's consistent. If that's the case I could use something like A Better Finder Attributes to copy the EXIF date to the Creation date, then Creation date to Modification date (I've suggested to them an option for both in one go).

    I have however been suggested to replace the affected files with my backups just in case they also have other problems.
    So is there a quicker way to do this than manually find and copy each file, one at a time?
    Even just syncing two Finder windows side-by-side (one for each hard drive) so that when opening up a specific folder of the source drive in the Finder the corresponding backup drive folder would open too, in another window. This would help immensly.
     
  4. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #4
    I would use rsync however there is probably a more Mac like way.
     
  5. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #5
    I thought Rsync was a command-line tool for making backups, but perhaps there's a way to use it to find/compare folder and file-paths since you suggest it?

    I'm thinking that if I can open two Finder windows where I have each window's base-folder defined I could from then on have some tool, script or whatever "sync" the rest of the path I so the exact same folder location open on each drive. Is this what you mean by using Rsync? If so, how?

    I was told that Pathfinder 7 could sync viewing two folders like this. I've downloaded the demo but couldn't figure out if this is true or how.
     
  6. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #6
    It takes 2 directories and makes sure they are "in sync". IIUC that what you want to do here...make one folder contain the same files, data and metadata as another.
     
  7. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #7
  8. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #8
    Cool! But since I don't know if the files have other problems I think I'll simply replace the offending files with the backups (keeping the old ones just in case of course) instead of fixing them.

    It does seem that I already have Rsync installed on my Mac (perhaps it comes with the OSX installation since I'm not sure if I ever installed it on its own) as I get a response when writing "rsync" in the terminal, but what do I do in order to sync two folder paths?
     
  9. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #9
    Yup. Rsync comes as standard.

    The command would be something like:

    Code:
    rsync -avz /path/to/first/folder/ /path/to/second/folder
    
    ...obviously, replacing the folder paths as appropriate. Note my trailing slash after the first path - I'll leave it as an exercise for you to find out what happens if you omit that (nothing bad, honest!).

    If you're not familiar with posix file paths then you can just drag the folders into Terminal and the path should appear.

    You can get all the details of how rsync works (or any other command line tool) by reading it's man page. Type:

    Code:
    man rsync
    
    I strongly recommend giving it a read and making sure you understand it before using rsync.

    Good luck.
     
  10. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #10
    DropSync is a gui program for rsync that will help you to get everything back in sync. Many times when I have used it instead of a quick command line usage of rsync I usually do, I have seen it say updating the modification time ... them type of things in its preview option you can get before actually doing the operation.
     

Share This Page