Mass remove character from file names and folder names

We have created a lot folders and files that contains the "<" character.

Is it possible to mass-remove these characters?


Solution 1:

I use Name Mangler 3 for file and folder renaming. There are free options out there, but Name Mangler offers a ton of features that make it well worth the $19.00 to me.

Here is Name Mangler on MacUpdate which includes links to many similar programs.

  1. Once you have Name Mangler installed, launch it
  2. Drag all of the folder you want to rename into the panel where it says "Drag Files and Folders Here"
  3. On the right choose "Find and Replace"
  4. Enter "<"
  5. Under "Replace with" enter the character you want to replace "<" with or leave blank to remove it
  6. Click "Rename x of x items"

Once of the many things that makes using a tool like Name Mangler valuable is that you can undo your changes, view a history of your changes, and create a "droplet" that make running the name change on other files really convenient. All of that plus being able to use Regex to build very complicated renames.

There is also a great Name Mangler Google Group where you can get your questions answered and some very advanced features and methods get discussed. They have been a big help to me.

Solution 2:

You can do this quite simply and quickly in Terminal:

cd /path/to/start/renaming

find . -name '*\<*' | while read f; do echo mv "$f" "${f//\</}"; done

The command above is a "dry-run" of the command below:

find . -name '*\<*' | while read f; do mv "$f" "${f//\</}"; done

This will remove any < characters recursively on files and folders starting from the path you cd into initially.

Result:

mv ./<folder<test<   ./foldertest
mv ./<test3.txt      ./test3.txt
mv ./test2<.txt      ./test2.txt
mv ./test<test.txt   ./testtest.txt

Solution 3:

What Worked For Me - filenames only

  • I gravitate toward terminal solutions because it's free and I've convinced myself I score style points.
  • I didn't need to remove all special characters, I only had to deal with ..., *, (, ), @ and leading underscores _ in a single directory.

cd /path/to/folder/with/offending/filenames/
for file in ./*
  do mv "$file" "${file//([ *\(\)@_$]|\.\.\.)/}"
done