September 1st 2010 – Version (2.3 Beta) is available. It adds the following new features:

  • A “Dry Run” mode. In this mode the application will only display and log the changes to the file/directory names without actually renaming the files and directories. This gives the user the ability to get an idea about what will be done before taking the plunge.
  • Fixes a bug where if a file or directory name contains only special characters, the renaming will fail and the recursive algorithm would try to keep going.

June 24th 2010 – Version (2.2 Beta). It adds the following new features:

  • Special characters could be removed from directory names as well.
  • It could be run in recursive mode that will allow renaming of all files and/or directories in all the sub-directories.
  • Removing all the dots in the file names but the last one that indicates the file extension.
  • The underscore is no longer considered a special character and it is not removed from the file names.


A few years ago I wrote a small application to remove all special characters from the file names of all the files in a directory.

Very often I would get a bunch of files that needed to be posted on a website and most of them would contain all kinds of special characters. I got fed up doing it manually- file by file, so I wrote this small app.

This is a Windows application written in C++ and works with win 98 and up. Of course Linux does not need anything like that, since you can do this with a quick one line shell command.

It only works with ASCII file names (sorry if you use any other language than English). I could have just as easily wrote it for UNICODE, but I had no need for that.

So, I decided to share it with anyone who wants to use it:

New v.2.3b: RenameFiles ver.2.3b
Old v.2.2b: RenameFiles ver.2.2 b
Old v.1.0:RenameFiles ver.1.0.

It is just a simple executable and does not need any installation. Keeping it simple is the key here. It also creates a log file in the same directory that the executable is in. The log file keeps track of the original file names and the new file names, so you can always find out what was done.

Quickly remove special characters from file names

108 thoughts on “Quickly remove special characters from file names

  • February 21, 2011 at 7:00 am
    Permalink

    great tool BUT
    I have some music downloads and some, maybe 5% of the files have illegal filenames and your tool does not seem able to correct these. Its sees the filenems and corrects it on the dry run but the real run comes up with error 3 file not found or some such

    Any ideas why?

    Elsewhere I read that the problem I have is due to incorrect characters in NTFS files on windows.

    Maybe your tool cannot make this correction because its cant write back to the NTFS file?

    Is this something that is fixable?

  • February 21, 2011 at 4:37 pm
    Permalink

    @ Denison,

    From the error it looks like it cold not rename them, not because it could not write but because the source file was not found. That means that these files have characters outside of the ASCII character set.

    What I would try is first using wild cards in command line, for example:

    ren *file1.mp3 new_file_name.mp3

    Here the “*” character will be the substitute of all the special characters.

    If that does not work, I suggest booting into Linux from a live CD. That should definitely take care of business.

  • March 1, 2011 at 10:48 am
    Permalink

    Could you tell me what characters are removed? Thanks.

  • March 1, 2011 at 3:01 pm
    Permalink

    @ Will,

    If the characters do not fall in any of the following categories, then they are considered special characters:

    – digits 0 through 9
    – capital letters A though Z
    – lower case letters a through z
    – underscore
    – blank space

  • April 19, 2011 at 4:04 pm
    Permalink

    Hello,
    I tried application to remove special characters from CZ language. Preview worked just fine, but real run did not find files because of CZ names.
    Beatifull things is, there was 700 files to rename and every one now shows message “file not found”
    Application cannot be ended in task manager only restart will solve this situation.
    Sorry, I would not recomend this to my friend ๐Ÿ™‚

  • April 19, 2011 at 6:01 pm
    Permalink

    @ anonymus,

    Please read before use! This application is not meant for any other language but English. Here is what it says in the description:

    “It only works with ASCII file names (sorry if you use any other language than English). ”

    Again, I made this application for my own use only and much later I decided to share it with everyone else who wants to use it. It is not a commercial product and my goal has never been to support everyone (and every language) out there. Sorry!

  • May 4, 2011 at 9:42 am
    Permalink

    Thank you. This was extremely helpful and saved a lot of time. Very kind of you to share it and make it easily accessible online.

  • June 11, 2011 at 11:29 am
    Permalink

    I tried it with filenames containing characters like ร‡ and รƒ, and it stripped those away just fine, those aren’t ASCII, are they?

  • June 11, 2011 at 1:26 pm
    Permalink

    @Tiago,

    I know they do not look like it, but they are actually ASCII characters. Take a look at the tables here: http://www.asciitable.com/. They are under the extended ASCII codes.

  • July 6, 2011 at 8:05 pm
    Permalink

    I was wondering if you could estimate when you would be putting out the unicode version. I only have one file that contains a “?” and nothing I’ve read has seemed to be able to remove it. Your program keeps producing and error cause = 3 for it. No rush just trying to recover some old files off a cell phone.

  • August 13, 2011 at 8:55 am
    Permalink

    Hi,

    I have a mp3 folder with some folders and files in unicode text format.is there any way to replace the unicode filenames and folder names with other characters because i am using linux and it doesnt want to open any of the folders…anybody know how i can proceed?

  • August 23, 2011 at 8:59 am
    Permalink

    Hi there,

    I just wanted to say thank you for this great little piece of software. I’ve had numerous files containing Japanese characters that cause one of my machines to crash and this will save me a lot of frustration.

    Thanks again.

  • August 26, 2011 at 2:14 am
    Permalink

    Awesome!! I’m sure this was no big deal for you to write, but this thing just made my life much easier!

    Way to go!!

  • September 16, 2011 at 11:34 am
    Permalink

    This is a GREAT tool, when do you think you will have time to add the “replace spaces with_” function?

  • October 11, 2011 at 9:34 pm
    Permalink

    I work in Cygwin so often get in trouble with crossing over.
    My messed up files contain question marks at the end of the filename, but can see they look like below.
    $ ls -b
    21078.xls\r 21232.vsd\r 24296.ppt\r 24347.doc\r
    The program renamefiles errors saying File 21078.xls? not found, cause = 3.
    But I was able to fix my files using a shell script with tr -dc ‘[:print:]’. I trick I found in this thread. Thanks!

  • October 12, 2011 at 12:23 pm
    Permalink

    Patrick, that’s simple:

    for x in *
    do
    mv “$x” $(echo “$x” | sed ‘s/\ /_/g’)
    done

  • October 19, 2011 at 9:19 am
    Permalink

    Hi Dimitar

    Iโ€™m from South Africa and a client that Iโ€™ve been working with requires all their product documents uploaded into a SharePoint library. There are about 40 500 files with around 3000 files that have characterโ€™s in the names. I found that out using SharePrep , unfortunately it is not a free tool. After searching a bit more I found your site. Thanks so much, your program has saved me a huge amount of time and effort. I just wanted to know could this also be done using powershell or management shell?

    Also I have another major problem. I need to upload all these files and specify the required metadata. Would you know how I can bulk upload with metadata?

    Thanking you in advance for your help.

  • October 20, 2011 at 11:41 am
    Permalink

    @Kercheval,

    I have no experience with MS power shell or management shell. I am not really a .NET person ๐Ÿ™ This is something fairly simple and if MS’s “power” shell cannot do this, then I doubt it could do anything! I just do not know enough about it to provide you with a script.

    Unfortunately I cannot give you a better answer for your meta-data problem. You will have to change the meta-data of the files before you upload them, not during. Also, depending on the file formats and what meta-data you need to change, there probably will be different tools for that.

    If you just want to preserve file meta-data like creation date, permissions, etc. when uploading them, take a look at the robocopy utility.

  • December 2, 2011 at 1:16 pm
    Permalink

    Hey! Thanks so much for this tool! Im looking to rename the files instead of replacing them. Do you think you could share the source so I can make the code change? I’ll email you all the edits I make so you can upload it back to this blog.

  • December 3, 2011 at 11:49 am
    Permalink

    @Darus,

    The program is already doing this. It renames the files. It does not replace them.

  • December 25, 2011 at 1:52 am
    Permalink

    Good day. Do you have a version one can run in cmd? No gui. Want it to rename stuff for me once a day. Would like to schedule it.

    PS Awesome little app.

  • February 6, 2012 at 6:16 pm
    Permalink

    Fine and Fast. How about replace Special Characters with a Space, then replacing Multiple Spaces with 1 Space. Would be an option I would use a lot…

  • February 29, 2012 at 9:34 am
    Permalink

    I am having the same problem as Jasper. Audio files (AIF) with a “?” in the file title. Actually the folder they are in has the same character. Every time I try to rename or do anything with them, I get a syntax error. I was excited for your software, but I am getting the same error as Jasper- 3. All the tools I have found online that claim to remove unwanted characters are unable to do it. I have tried with more than one computer, and it seems pretty clear to me that it is not my machine causing the problem. Anyway thought I would mention it. Thanks for your software- the search continues!

  • September 26, 2012 at 8:44 pm
    Permalink

    Here’s a start at removing special characters via powershell. Could certainly be made more refined in to a cleaner script. Should remove special characters from files and directories (and subdirectories and files). Will raise an error if a name doesn’t have a special character but does continue on. Change to your working directory before you begin or update the -path for get-childitem.

    Like I said, it needs work. ๐Ÿ™‚

    get-childitem -Path . -recurse | ForEach-Object { Rename-Item -path $_.fullname -NewName ([System.Text.RegularExpressions.Regex]::Replace($_.name,”[^1-9a-zA-Z_. ]”,””)); }

  • May 30, 2013 at 9:02 pm
    Permalink

    This is great, thanks for shareing with us all, has saved me from 1000’s of manual renames and unreliabe perl scripts

  • July 23, 2013 at 6:36 am
    Permalink

    Could you please make the removing of dots optional – or even better to be able to specify how many dots starting from the last one will be removed. I’am using it to clean out Trackmania map names ๐Ÿ˜€ but the game needs the end of the file to be map_name_here.Map.Gbx

  • July 26, 2013 at 6:57 pm
    Permalink

    THIS IS THE GREATEST APPLICATION OF ALL TIME!!! GOD BLESS THE PERSON WHO MADE THIS, YOU HAVE SAVED ME FROM EXTINCTION. I’M RECOMMENDING YOU FOR AN EMMY AS WELL AS THE NOBEL PEACE PRIZE.

  • August 30, 2013 at 1:37 pm
    Permalink

    thanks – so very useful. you saved me so much time.

  • October 14, 2013 at 5:27 am
    Permalink

    I tried it but it doesn’t work with names containing colon “:”.
    When I preview changes, it gives correct results, but when I try to apply then it returns an error (error 2, error 3 etc).
    It seems really impossible to remove colons from filenames in Windows! ๐Ÿ™ so sad

  • October 28, 2013 at 3:14 pm
    Permalink

    Hallelujah!! this is exactly what I was looking for!!!!! thanx!!!

  • February 3, 2014 at 8:37 pm
    Permalink

    Any chance we can have a peek in the code or anything like a tutorial to find-loop-rename so we can learn ๐Ÿ™‚
    Thanks

  • April 2, 2014 at 1:04 pm
    Permalink

    gnome-screenshot took all my screenshots in date time format. Ofcorse time was HH:MM:SS, so windows has problems with colon (:) character. I was hoping this program of yours would deal with that, but it doesn’t. I can’t even rename those files by hand even if they are visible in windows explorer?!?

    Such feature would come in handy… just saying…

  • April 8, 2014 at 8:19 am
    Permalink

    Thank you so much for sharing! Saved me time.

  • June 26, 2014 at 12:56 am
    Permalink

    very useful. thank you very much.
    but I need to remove dots only from the beginning of file names. is there any option to do this?

  • July 7, 2014 at 8:00 am
    Permalink

    Hello,
    I tried it on an external hard disk and it does not work for files containing colons. Il tells me file not found cause 3. When I try Dry Run mode it works fine telling me the new name of my files. Version used : 2.3 Beta
    Please help.
    Thanks.

  • July 30, 2014 at 12:59 pm
    Permalink

    A better one-liner is

    for f in *; do mv “$f” “`echo $f | tr -cd ‘ -~’`”; done

    as in, I think, another post of yours, but it saves all the non-control ASCII codes. It needed a little tweaking to allow a space inside the destination filename.

  • December 3, 2014 at 4:24 pm
    Permalink

    Hi,

    This is a great tool, which has save me a lot of time.

    Thanks a lot for sharing this to the online community.

    Also, is there a way you can update this application, so that when you rename a file and the name already exist in the same folder, it appends the name with a number at the end instead of showing a error and ignoring the file.

  • December 13, 2014 at 1:26 pm
    Permalink

    Dry Run works OK but fails to Process changes. It says all the files are “not found”.

  • December 16, 2014 at 11:34 am
    Permalink

    Is there a way to configure character replacements? For example all the “&” will be replaced with “and”, while all the “%” will be replaced with “perc”, I am willing to donate some money to have this be a feature if possible, feel free to e-mail me if you are interested.

  • January 6, 2015 at 8:59 am
    Permalink

    Hi,

    I got the same problem and my solution was to use Windows short names. Use the command “dir /x” to see the short name (abcdef~1) of your file or directory.
    You can easily rename the file/folder using the short name in command line (ren abcdef~1 my_new_folder_name).

  • February 24, 2015 at 7:39 am
    Permalink

    Great little application. Saves a boat load of time, we had a similar function running via command line scripts, but this is much cleaner. We would be willing to donate money for two features:

    The option to output to a log file rather than just the screen.

    The option to incramentally rename files when you see error = 5 – I assume the “Error = 5” indicates that renaming the file couldn’t take place because there is another file in the same directory with the same resulting filename. Meaning if these two files are in the same directory:

    bad^file.txt
    bad)file.txt
    bad$file.txt

    Then only one gets renamed, because the second would result in a filename that already existing in that directory. If the result could incriment the filename to get around the issue:

    badfile.txt
    badfile1.txt
    badfile2.txt

    And so on, it would get around the “error = 5” problem.

  • March 25, 2015 at 7:00 am
    Permalink

    Dear Dimitar, your program saved my day – I encountered some (actually a couple of thousand) problematic files that I have to transition from an oracle IFS share to a a common NTFS share.
    It might not be perfect – a nice touch would be to include an option to select which special characters you would allow, like a dot. Nevertheless, many thanks!!

  • April 1, 2015 at 3:03 pm
    Permalink

    Great tool! Is there a way for me to add this script into SharePoint so that when users are attempting to upload files it checks their filenames and fixes them according to established naming conventions (i.e., replaces spaces with “_” and removes illegal characters or replaces “.” with “-“? It would be nice to have a way to control naming conventions upon upload so that files do not need to be renamed after the fact.

    Also, would it be possible to provide the script text so I can customize it?

    Thanks!!!

    Thanks!

  • May 13, 2015 at 3:01 pm
    Permalink

    Great tool.

    I sugest the dry run option to be default selected, and in case it is not, after pressing “process” a confirmation window pops, alerting that the files will be renamed.

    Thank you.

  • August 22, 2015 at 8:36 pm
    Permalink

    A very useful enhancement would be to choose the “special characters” to remove. Personally, I remove all non-alphanumeric characters; with exceptions of not modifying the file-extension, the final ‘.’ character, as well as simply replacing []()-. and space with an underscore. I don’t like spaces, but they are very prevalent in Windows filesystems. I primarily use replacement for removing the latin unicode characters and !@#$%&^*?><+=`';, characters.
    Thanks for listening!

  • September 28, 2015 at 10:00 pm
    Permalink

    Very useful. Small suggestion. I the list of special characters can be configured say from a txt file then it would be great. In my case I need to remove underscore also.

  • November 9, 2015 at 2:06 pm
    Permalink

    THANK YOU!!!

  • February 1, 2016 at 12:20 pm
    Permalink

    IF RENAME DOESN’T FIX THE FILE
    re: jasper, 2010, his mp3 file

    Dead file renaming sneaks up on you when the total pathname character length goes over 255 chars in Windows (all versions — it’s the file system). This is common in photo and mp3 collections. The problem looks like and “access control” “being used by another process” issue, or like an illegal char problem. If you don’t have special ute for dealing with this “Delete Invalid File” “Delete Doctor” (they’re awkward anyway), try abbreviating folder names in path above bad file folder.

    Sorry if this answered already in very long thread — I had been around this block and wanted to help.
    Regards and thanks,

  • February 14, 2016 at 4:31 pm
    Permalink

    This software does not work with Windows 7 64 Pro, just as some other people wrote: OK in “dry mode” but files are not found when trying to rename them for good. This is an old bug (2010!) still not corrected.

  • February 19, 2016 at 3:15 pm
    Permalink

    Thanks so much for making this tool. You rock!

Leave a Reply

Your email address will not be published. Required fields are marked *

*