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.

How can I replace this character (_) with this one (:) in a list of filenames? The filenames are like this: 1_0_1_1AE1_7F6_2_11A0000_0_0_0.png The problem with character replacement programs is that the : character is illegal for filenames so they return errors.

Any ideas on how to bypass this?

share|improve this question
4  
Please include the operating system you are working with. –  terdon Jan 15 '13 at 15:51
    
You want to actually rename the files, or to get a textual list and replace the characthers in a text editor or something? –  That Brazilian Guy Jan 15 '13 at 16:22

1 Answer 1

This is how you would write the script, but, as you mention in the OP, you still have the issue of the : being an illegal character. And IMO there is no way around this on Windows, illegal characters cannot be used!

@echo off
echo Enter Filename
set /p name=
set newName=%name:_=:%
ren %name% %newNname%

This is within a loop

@echo off
setlocal enabledelayedexpansion
for /f "delims=;" %%name in ('dir /b FOLDERNAME') do (
set newName=%%name
set newName=!newName:_=:!
ren %%name !newName!
)
share|improve this answer
    
You need to add setlocal enabledelayedexpansion and change the %newName%'s to !newName! in the for loop version :) –  Bali C Jan 15 '13 at 15:53
1  
Just move the setlocal line above the for and change %newName:_=:% to !newName:_=:! and your good to go :) However, I don't know if this will allow colon's in filenames? At least on windows. –  Bali C Jan 15 '13 at 15:56
    
ah man.. I just actually tried it - instant fail! Thanks @BaliC –  Dave Jan 15 '13 at 15:58
    
%variable - Specifies a single letter replaceable parameter, so %%name is actually incorrect (it might work since it's being truncated to a single letter, but it is incorrect). –  Karan Jan 16 '13 at 1:51

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.