Check the answer found here
https://apple.stackexchange.com/questions/52535/clean-up-file-names-using-automator
I changed the bash script code to include the date code.
shopt -s extglob
dcode=`date '+%m%y'`
for f in "$@"; do
f1="${f%.*}"
f2="${f##*.}"
if [ "$f2" == "$f1" ] ; then
echo "$f" "${f1}_${dcode}"
else
echo "$f" "${f1}_${dcode}.${f2}"
fi
done
The code will should work even with files that do not have extensions.
Replace the commands echo with mv to actually get the code to do anything.
Hope that helped.
You can do this with an AppleScript. Use the Script Editor in the Utilities folder. Here is a script I wrote for you just now. It works on one folder at a time-- not the top level folder, but the one in your example that is 3587915.
When you run this script it asks you to choose a folder. In this example you would open 3587915 and then click "Choose." Very important: don't choose your 3589919. We are only working on one folder at a time here. If this works for you we can expand to looping through the folders in the top-level folder.
tell application "Finder"
set the_folder to choose folder
set the_folder_name to name of the_folder
set the_subfolders to every folder in the_folder
repeat with I from 1 to count of the_subfolders
set name of every file of item I of the_subfolders to the_folder_name & "_" & I & ".pdf"
move every file of item I of the_subfolders to the_folder
end repeat
--
-- optionally delete the subfolders
delete every folder in the_folder -- put two dashes in front of this line to comment it out
end tell
Here are screenshots showing you how it works. You should practice on a set of folders that don't matter at first. You can see my starting set-up in the first picture and the result in the second. The captions on the pictures are not showing up (for me) so here is what they should be:
Picture 1: Automator Service, with slightly modified AppleScript.
Picture 2: folder_1, folder_2, folder_3, folder_4, and folder_5 each have a single pdf in them. Only folder_1's contents are shown here.
Picture 3: This is the result. The subfolders are gone. The files are named after the parent folder.
You can save the script as an app. Or, you can run the script within a step in Automator since Automator can run an AppleScript. That's in the Utilities section of Automator, "Run AppleScript." I would include a picture but I am new here and am only allowed two pictures until I am upgraded.
If you want to do it with a service, you use almost the same script, but you have to pass the control-clicked folder. Rather than using the AppleScript step "Choose Folder" you tell your Automator Service to "receive selected folder in the Finder" and you set "the_folder" to item 1 of the input. See the first picture. Works like a champ here!
Best Answer
If the files are in the same folder, go to Finder and select all the files you want to rename. Then right-click on them and one of the options is to rename xxx items where xxx is the number of files selected. When you select this option it opens a panel where you can enter how you want the files renamed. Then you can select rename and all the files will be renamed.
Or from the command line use
ls *.ext
where ext is the extension of your file names, in your case pdf. If the ls command listed just the files you want to change the name of usecp *.ext newFileName.ext
to copy the files to a new file name or usemv *.pdf NewFileName.pdf
to move the files.