Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to replace all the underscore characters (_) with a space () in a filename.

How can I do this quickly, when I have lots of _ characters to replace?

share|improve this question
4  
As the answers are indicating, there /is/ no way to do this in Explorer. You need a script or a batch file renamer. –  Shinrai Oct 8 '10 at 14:39

5 Answers 5

up vote 11 down vote accepted

vbScript should do it for you. Create a file called "rename_underscores.vbs" containing the following.

Set objFso = CreateObject("Scripting.FileSystemObject")
Set Folder = objFSO.GetFolder("c:\test\")

For Each File In Folder.Files
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"_"," ")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next

Make sure the folder name is correct. (In the example, I've used c:\test) And then double click your file to do the renaming.

share|improve this answer

Windows-based renaming tool, the most powerful there is, and it's free. http://www3.telus.net/pfrank/

share|improve this answer

This is within the realms of a dos bat file. Create a bat file (New->Text file, rename extension to .bat) then copy the blue sections below into it.

I'll split it into sections and explain what it's doing.


Print the current state of the directory for comparasson later

dir /b

List the files in the directory, then for all the ones that contain an underscore and end in .txt, call ProcessFile on them.

for %%f in (*_*.txt) do call :ProcessFile %%f
goto :finished

The syntax "str=%str:x=y%" replaces instances of x with y. In this case, we're replacing "_" with nothing

:ProcessFile
set str=%1
rename %1 %str:_=%
goto :eof

That's it!

Now it just prints what was changed so we can confirm it's working as expected;

:finished
echo ----
dir /b

Results (Not part of the bat file)

baz_ing.txt
big_rawr.foo
foo_bar.txt
multiple_underscores_test.txt
----
bazing.txt
big_rawr.foo
foobar.txt
multipleunderscorestest.txt
share|improve this answer

I recommend using a 3rd party tool like Bulk Rename Utility. It's free and it has an installer less than 1 MB.

share|improve this answer
1  
What if the file name is "this_is_a_test.ext"? –  seanyboy Oct 8 '10 at 13:45
1  
Bulk Rename Utility is a GREAT applications. Its very versatile and i don't think you can achieve the same with Explorer. –  Alex Angelico Oct 10 '10 at 0:08
    
The dos command would be a little more complicated than that. I'll mock one up. –  RJFalconer Nov 21 '10 at 12:55

Here is my batch rename ruby script. I haven't used other batch renaming tools but I think my script is very easy to use and very versatile. Here is the command for your case:

ruby bren.rb *_* "_/ "

I have setup my windows environment in such a way bren.rb can be executed as an executable from any directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.