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 need to remove the first character (which is always "_") from all filenames in a folder.

I'm currently using this command: ren _*.txt *.txt But it doesn't work.

However, if I run ren _*.txt A*.txt it perfectly works, but it is not what I want.

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

again, try powershell ;)

Run this in your desired directory:

gci *.txt | rename-item -newname { [string]($_.name).substring(1) }

Explanation: - gci *.txt collects all *.txt-files in the actual directory.
- rename-item -newname renames the piped results from the gci-command with the string that is generated in {}
- string.substring(1) takes the filename starting after the first character

share|improve this answer
    
hey, it says gci is not recognized as an internal or external command –  Patrick Apr 20 '11 at 12:30
1  
hm... this should work...however. gci is per default an alias for Get-Childitem - take that instead. Did you run powershell? It doesn't work if you tried that in cmd.exe (but you can start powershell.exe from within cmd) –  wullxz Apr 20 '11 at 12:32
    
all right, now it works. I still have a small issue, the first character is actually a ".", so I have 2 initial characters to remove "._filename.jpg" and not "_filename.jpg". Do you how to deal with the dots ? –  Patrick Apr 20 '11 at 12:40
1  
if you want to remove the first 2 characters, just replace the (1) after 'substring' with (2). In powershell, the whole filename is treated as a string(-object), points included. –  wullxz Apr 20 '11 at 12:43
add comment

If you want to avoid having to write anything, try the Bulk Rename Utility. The interface can be quite scary at first but just have a play around with it and you'll see it's not actually hard to use at all.

share|improve this answer
add comment

Just if anyone needs in future: I use 1-4 rename. It is fast, does not have to be installed. When you run it hit F2 for advanced mode and you can tell it to kill the first 4 characters. Below is the link to the program.

Download Link: http://www.1-4a.com/rename/

share|improve this answer
add comment

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.