Need script or app to convert filenames and folder names from day/month/year order to year/month/day I have recently been sent a large number of tif files where for some misguided reason the file names have all been recorded in DD/MM/YY format ie 130307 whereas I need it as YYYY MM DD. The files are also prefixed as shown here:
GC Mins 130307 004.tif (this can stay although the chance to modify it would also be welcome).

The files are sitting in folders themselves also named in similar fashion so:
07 Dec
08 Jan
13 Oct

These too need to be converted to read yyyy mm dd.

Any help appreciated on what to do to overcome this issue as brute force renaming is not really on given the number of files which number in the 000s.
Apart from TJ Luoma's third-party solution (a fine solution for long-term situations, but perhaps not something you wish to pay for if this is a one-time endeavour), no one has yet offered a programmatic solution to your dilemma.

I waited until now because, admittedly, despite your screenshots, I still don't have a clear picture of your folder structure (in general, notwithstanding the two specific examples you supplied), so was hoping someone else would have interpreted what I couldn't, and posted a solution.

However, I then noticed your final comment, which spares me the need to interrogate you further about what's what:


  At the end of the day we wish to consolidate all the files into a single year folder so we need to be able to sort them in order.


This means that, provided all the images in question are located within a single directory tree that doesn't contain other images files that aren't intended to be processed along with them, I can hopefully solve your problem for you:

property this : a reference to current application
--------------------------------------------------------------------------------
###USER-DEFINED PROPERTIES
property rootdir : "~/Example"
property imgTypes : ["tif", "tiff", "png", "jpg"]
property moveFiles : no
property moveTo : rootdir
--------------------------------------------------------------------------------
###IMPLEMENTATION
#
#
tell the directory to filter by imgTypes
reformatFilenames() of imageFiles

if moveFiles ≠ yes then return
tell the imageFiles to move
--------------------------------------------------------------------------------
###SCRIPT OBJECTS &amp; HANDLERS
#
#
script directory
    use framework "Foundation"

    property NSDirectoryEnumerationSkipsHiddenFiles : a reference to 4
    property NSFileManager : a reference to NSFileManager of this
    property NSPredicate : a reference to NSPredicate of this
    property NSString : a reference to NSString of this
    property NSURL : a reference to NSURL of this
    ------------------------------------------------------------------------
    property images : null
    ------------------------------------------------------------------------
    to recurse thru directory
        local directory

        set FileManager to NSFileManager's defaultManager()

        FileManager's enumeratorAtURL:(NSURL's ¬
            URLWithString:((NSString's ¬
                stringWithString:directory)'s ¬
                stringByStandardizingPath())) ¬
            includingPropertiesForKeys:{} ¬
            options:NSDirectoryEnumerationSkipsHiddenFiles ¬
            errorHandler:(missing value)
    end recurse

    to filter by filetype
        local filetype

        recurse thru rootdir
        set images to (result's allObjects()'s ¬
            filteredArrayUsingPredicate:(NSPredicate's ¬
                predicateWithFormat:("pathExtension IN %@") ¬
                    argumentArray:[filetype])) as list
    end filter
end script

script imageFiles
    use framework "Foundation"

    property NSMutableArray : a reference to NSMutableArray of this
    property NSRegEx : a reference to NSRegularExpression of this
    ------------------------------------------------------------------------
    to matchString against pattern from str into fmt
        local pattern, str, fmt
        local results

        set results to NSMutableArray's array()

        NSRegEx's regularExpressionWithPattern:pattern ¬
            options:(NSRegularExpressionCaseInsensitive of this) ¬
            |error|:(missing value)

        set RegEx to the result

        repeat with match in (RegEx's matchesInString:str ¬
            options:0 range:[0, str's length])

            (results's addObject:(RegEx's ¬
                replacementStringForResult:match ¬
                    inString:str ¬
                    offset:0 ¬
                    template:fmt))
        end repeat

        return the results as list
    end matchString

    to reformatFilenames()
        tell application "System Events" to repeat with img in ¬
            (a reference to |images| of the directory)

            set fp to the POSIX path of (img as alias)

            set [fname] to (matchString of imageFiles ¬
                against ("(.+)/(.*?)( )?" &amp; ¬
                "((\\d{2})(\\d{2})(\\d{2}))" &amp; ¬
                "( )?([^/]+)") ¬
                from fp ¬
                into "$1/19$7-$6-$5$3$2$8$9") &amp; {null}

            if fname ≠ null then set ¬
                [name of file fp, fp] to ¬
                [fname, fname]

            set contents of img to file fp
        end repeat
    end reformatFilenames

    to make (dir as text)
        tell application "System Events" to if not (folder named dir in ¬
            folder moveTo exists) then make new folder at ¬
            folder moveTo with properties {name:dir}
    end make

    to move
        tell application "System Events" to repeat with img in ¬
            the directory's |images|

            set y to the first word of (img's name as text)
            tell imageFiles to make y
            move img to the folder named y in folder moveTo
        end repeat
    end move
end script
---------------------------------------------------------------------------❮END❯


System info: AppleScript version: "2.7", system version: "10.13.6"

What This Script Does:  Given a path to a source (root) folder under which all your images are contained somewhere within any subfolder, this script will obtain the entire contents—files, folders, packages, aliases, etc.—of the directory tree whose root is at the source folder specified.  Hidden files are ignored.  It then filters all of these items to isolate only those with a file extension matching a pre-determined list of valid extensions supplied.  The filtered array of files is then iterated through one-by-one to rename each file according to your already-stated specifications (more about this below).  If needed, the renamed files are moved to a new location, organised under a top-level directory specified by the supplied filepath that points to an existing folder on your system.  The files are sorted into subfolders labelled by year, e.g. "1994".  If the subfolder does not exist, it is created.  Pre-existing files were not overwritten in my testing, but this may be dependent on your version of AppleScript and macOS.

Utilising This Script: You can copy and paste this script into Script Editor and run it from there.  There are four user-defined properties near the top of the script that you can (and should) edit to your needs:


rootdir: The top-level folder of the directory tree within which the image files to be processed are located.  The files can be located in the top-level folder itself, or in any sub-directory contained therein.  This should be a posix path (slash notation), and using a tilde (~) to represent the home directory is fine, as would be a full filepath.
imgTypes: A list of file extensions (without the leading period) that will be used to discriminate the types of files to be processed.  The images in your screenshots all have extension "tif", so you can leave this property as it is, or add extra extensions if needed, e.g. "gif".
moveFiles: yes to have files relocated to a single folder after being renamed; no to leave them where they are (don't put quotes around yes or no).
moveTo: The destination directory to where the images will be moved and organised into subfolders after renaming.  If moveFiles is set to no, this property is ignored and won't affect anything in the script.  Otherwise, the path supplied must, once again, be a posix path to an existing folder, which can be the same as rootdir, or any other folder on your system.  The subfolders for the images need not exist beforehand, as these will be created on a per need basis by the script.


A Few Warning Guidelines: Note that this script uses System Events to handle the file renaming and moving.  Therefore, there are no undos.

Unless you're confident with AppleScript (and specifically AppleScriptObjC) and regular expressions (used in reformatting the filenames), I'd advise against editing any other parts of the script yourself.  Doing so would likely just cause the script not to work, which would be fine; but it might instead end up processing and renaming files you didn't intend it to, and you don't want that.

For this reason, I would also suggest you trial this script on a small set of dummy files and folders yourself to ensure it does do what you are wanting before you apply it to your actual files.  It's also worth making a backup of your photographs beforehand, just to be extra safe.

All warnings aside, I don't anticipate any problems if I've understood your needs correctly, and you've understood what this script is designed to do.  If you're not sure, feel free to ask for clarification.

I've tested it on files with file name variations, and various distributions throughout a nested set of folders without no issues.  (But, naturally, this only means there are no issues under the conditions that I was able to think up).

How Files Are Renamed: If a file is to be renamed, it's current filename must contain a six-digit number representing a 20th-century date in the format ddmmyy.  If there are more than one occurrences of a six-digit number pattern in the filename, it is the first occurrence that is assumed to be the date string.  The rest of the filename can be anything, both before and/or after the date string, e.g. "%prefix% %ddmmyy% %suffix%.tif".  Neither the prefix nor suffix part of the filename, nor the spaces, are mandatory, so a filename consisting simply of "%ddmmyy%.tif" is considered valid for processing.  The filename is then reformatted by swapping the positions of the prefix (if present) and the date string, leaving the rest as it is.  The date string is also reformatted into ISO-standard international date format, i.e. yyyy-mm-dd.  This includes the hyphens (let me know if you want the hyphens omitted, as I know this wasn't part of your original specification, but it's standard filenaming practice to have them present).  To summarise the filename change by way of examples:

① "Editorial Com Mins 080594 003.tif" → "1994-05-08 Editorial Com Mins 003.tif"
② "1994-05-08 Editorial Com Mins 123456.tif" → "1956-34-12 1994-05-08 Editorial Com Mins.tif"
③ "080594.tif" → "1994-05-08.tif"
④ "1994-05-08 Editorial Com Mins 02.tif" → "1994-05-08 Editorial Com Mins 02.tif"


Note in the second example that the filename might already have been formatted appropriately to begin with, however the presence of a six-digit number pattern meant that it was processed by the script.  However, in the fourth example, the absence of a six-digit number pattern leaves the filename unchanged.