editing file names

I would like to edit 1789 files that contain a “-” in them.
They were not suppost to be “-” they were suppost to be
an “_”. Is there an easy way to change the names of
all 1789 files.

one example would be “drag_rifleman-051.kit” to “drag_rifleman_051.kit”

they are of no specific kind and they are all in different subfolders of
a folder named “HX5”. Please help. or my fingers will be sore.

When I went to OS-X I found I had a lot of files with ‘/’ in them, which caused all sorts of problems. This script does what you want, I changed the search character to the “-” as you required.

tell application “Finder”
set targetFiles to every file of (entire contents of (choose folder)) whose name contains “-”
repeat with currentFile in targetFiles
set newFileName to my getNewFileName(name of currentFile)
set name of currentFile to newFileName
end repeat
end tell

on [color=green]getNewFileName/color
set {oldDelims, my text item delimiters} to {my text item delimiters, “-”}
set name_parts to text items of oldName
set my text item delimiters to “_”
set newName to name_parts as string
set my text item delimiters to oldDelims
return newName
end getNewFileName


Thank you so much!
and you replied so fast. :lol: