8 Replies Latest reply: Mar 8, 2015 1:59 PM by Paul Collins
Philip Caplan Level 1 Level 1 (0 points)
Hello All

I have a folder containing 40 subfolders, and inside each of these subfolders are a number of files (between 4 and 45 each) totalling over 500 files.

Each filename starts with a string "orginalstring".

What I would like is the easiest way (whether using Automator or not) to replace all 500+ "orginalstring" with "replacementstring".

Many thanks for your help. Philip

iMac Intel, Mac OS X (10.4.1)
  • rccharles Level 5 Level 5 (6,485 points)
    perhaps ABetterFinderRename version 7.9.9.3 for Tiger would be of help.

    http://www.publicspace.net/ABetterFinderRename/

    Robert
  • Andrew99 Level 4 Level 4 (1,300 points)
    You might try the example workflow below. It uses actions found under Automator's Finder library:

    1) *Ask for Finder Items* -- Type: Folders

    2) *Get Folder Contents* -- Check "Repeat for each subfolder found."

    3) *Rename Finder Items* -- Click the popup button and select "Replace Text."

    Enter into the respective text fields: Find: originalstring; Replace: replacementstring.

    Choose Run from Automator's Workflow menu. When the Choose Folder dialog appears, select the parent folder and press Choose.

    If desired, the workflow can be saved as an applet. From Automator's File menu, select Save As... > File Format: Application.

    Good luck.
  • Philip Caplan Level 1 Level 1 (0 points)
    That's it! Thanks very much for your help, Andrew66.
  • Andrew99 Level 4 Level 4 (1,300 points)
    I'm glad that helped! Thanks for posting back.
  • Marc D Level 2 Level 2 (320 points)

    Andrew99, thanks for those instructions.  I was able to convert about 12K emlx files to eml files (from dozens of subdirectories) while migrating from Entourage to Thunderbird (Windows).  Too many problems with Entourage and I can't afford a new Mac right now. 

     

    It was my first time using Automator and it was easy and straighforward.  You saved me a lot of time!

     

    - marc

  • PJB1977 Level 1 Level 1 (0 points)

    Although the original poster's problem is long solved and it doesn't directly help.  Here is an appleapplescript that will perform a batch rename of selected files with ne names provided in a .csv file.  SImply open applescript, paste in an run.  Its not the most robust - it will fail if you try to create duplicate files, but for the most part it does a good job for a quick and dirty.... Beanlander

     

    ---

    -- Bulk Rename files from .csv file

    on run {}

       

        set file_NewFilenames to choose file with prompt "Choose .csv file containing new filenames"

        set files_ToBeRenamed to choose file with prompt "Choose files to be renamed" with multiple selections allowed

       

        set filedata_NewFilenames to read file_NewFilenames

        set list_NewFilenames to paragraphs of filedata_NewFilenames

       

        -- determine the maximum number of files that can be renamed

        set num_MaxFilesToRename to count of list_NewFilenames

        if num_MaxFilesToRename > (count of files_ToBeRenamed) then

            set num_MaxFilesToRename to count of files_ToBeRenamed

        end if

       

        --display dialog "Renaming " & num_MaxFilesToRename & " files…"

       

        repeat with i from 1 to num_MaxFilesToRename

            try

                set fileToBeRenamed to item i of files_ToBeRenamed

                set newName to item i of list_NewFilenames

               

                set AppleScript's text item delimiters to "\""

                set newName to (text items of newName)

                set AppleScript's text item delimiters to ""

                set newName to (newName as string)

               

                --display dialog newName as text

               

                tell application "Finder"

                    set filenameExtension to name extension of fileToBeRenamed

                    set name of fileToBeRenamed to newName & "." & filenameExtension

                end tell

            on error

                display dialog "Could not rename: " & fileToBeRenamed giving up after 3

            end try

        end repeat

    end run

  • PJB1977 Level 1 Level 1 (0 points)

    And here's a similar script that does batch touch to set the filetimestamp from a .csv file.

     

    -----

    on run {}

        -- courtesy of the Beanlander

        -- new dates in touch format [[CC]YY]MMDDhhmm[.SS]   

        set file_NewDates to choose file with prompt "Choose .csv file containing new dates"

        set files_ToBeRenamed to choose file with prompt "Choose files to be renamed" with multiple selections allowed

       

        set filedata_NewDates to read file_NewDates

        set list_NewDates to paragraphs of filedata_NewDates

       

        -- determine the maximum number of files that can be touched

        set num_MaxFilesToTouch to count of list_NewDates

        if num_MaxFilesToTouch > (count of files_ToBeRenamed) then

            set num_MaxFilesToTouch to count of files_ToBeRenamed

        end if

       

        --display dialog "Renaming " & num_MaxFilesToTouch & " files…"

       

        repeat with i from 1 to num_MaxFilesToTouch

            try

                set fileToBeTouched to item i of files_ToBeRenamed

                set newDate to item i of list_NewDates

               

                tell application "Finder"

                    set fileName to POSIX path of fileToBeTouched

                    do shell script "touch -t " & newDate & " " & quoted form of fileName

                end tell

            on error

                display dialog "Could not touch: " & fileToBeTouched giving up after 3

            end try

        end repeat

    end run

  • Paul Collins Level 1 Level 1 (45 points)

    Nice concise answer.

     

    I found that to get it to rename files inside folders (recursion), checking "Repeat for each subfolder found" was not enough. I also had to add this step between

    Get Folder Contents and Rename Finder Items:

     

    Filter Finder Items - All, Kind is not Folder.

     

    My renaming was actually adding file extensions using "Add Text" in the Rename step.