7

I have a bunch of files named similar to this:

1_1.pngEND1_1.png

How would you replace .pngEND with _?

I've googled this problem and tried literally 5+ solutions, non of which worked on mac.

2
  • If you edit your post to detail one solution you sel cited to try and the link you used, we might be able to correct what doesn't work for you. (Or point to a better tool to batch rename files). I'd use bash or Python depending on how easy a restore from backup was, but those tools or just using mv could backfire if you're not already good with the syntax needed..
    – bmike
    Apr 12, 2017 at 8:46
  • 2
    I suggest that you look at the venerable perl rename- search.cpan.org/~pederst/rename-1.9/bin/rename.PL
    – fd0
    Apr 12, 2017 at 12:44

5 Answers 5

9

There are tons of ways to do this, for instance

for i in *pngEND*.png; do [[ -e ${i/.pngEND/_} ]] || echo mv "$i" "${i/.pngEND/_}"; done

Remove the echo if the output looks sensible.

0
20

Unless you need a solution you can use in a script, you can do this directly in Finder.

  • Select the files you want to rename
  • Right click one of them, and choose Rename N Items... (where N is the number of selected files)
  • Choose the Replace Text option in the dropdown
  • Enter the text you want to replace (".pngEND") and the text you want to replace it with ("_")
  • Click Rename
2
  • 1
    This is great but is there a way to do this recursively? Jul 20, 2021 at 16:34
  • Depends what you mean by recursively. It will happily rename files in multiple different folders in one go, but you will still need to manually find and select them all first before selecting Rename.
    – calum_b
    Jul 22, 2021 at 14:32
2

If your not familier with terminal or scripts, you can use the mac app called NameChanger (free to use). You can change almost everything in batch on filenames / file extentions.

1
  • 1
    For this specific type of batch rename, though, there's no need for 3rd party apps--Finder can do it.
    – calum_b
    Apr 12, 2017 at 10:58
1

If I had to do this, I'd use rename command available for install via HomeBrew.

Example:

Setup:

mac:test user$ touch 1_1.pngEND1_1.png

mac:test user$ ls
1_1.pngEND1_1.png

Run rename command:

mac:test user$ rename 's/\.pngEND/_/' *.pngEND*

Result:

mac:test user$ ls
1_1_1_1.png
1

I've also used the perl rename tool to some success. It also has a dry run option so you can test before you execute the changes.

2
  • Do I need to install anything to use perl commands?
    – sanjihan
    Apr 12, 2017 at 20:31
  • That just the history. It's just a tool contained in the package manager that can be used on Linux/GNU-based environments. It may be in it's own like perl-rename.
    – Pysis
    Apr 12, 2017 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .