Windows Batch File Rename to Replace %20 Characters with _
I have a folder with a lot of files that I need to rename. The
original format for example is ABC%20DEF%20GHI%20JKL.xyz. What I
need to do is to replace each %20 with _. So essentially I'm
parsing out the %20 characters from the file names and then replacing
those with an underscore _ character.
Ideally I'd like to be able to complete this with a script rather than
an application.
Warning: If you are asking where to start to learn how to do this with batch and rename command, then this question will be tagged as off-topic more than likely (see Techie007 response in comments below my answer).
Below is a batch script example that replaces all %20 characters from file names and replaces them all with underbar\underscore _ characters. So you can look over it and see if that gives you some starting points as well. This will complete the task you're tring to accomplish otherwise, per your inquiry, and either of the two ways it can be interpreted without further clarification.
I'll post some resources for learning below the batch script though, and that'll be additional learning resources for starting points too.
Batch script example to parse %20 and replace with and underbar _ with batch for files in a particular directory.
@ECHO ON
SETLOCAL DISABLEDELAYEDEXPANSION
SET rendir=C:\Path\FolderPath\WithFilesToRename
FOR /F "USEBACKQ DELIMS=" %%N IN (
`DIR /A-D /B "%rendir%"`
) DO (
SET "Var=%%~NXN"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "Orig=!Var!"
SET "Var=!Var:%%20=_!"
IF NOT "!Var!"=="!Orig!" (
IF NOT EXIST "%%~DPN!Var!" (
REN "%rendir%\!Orig!" "!Var!"
) ELSE (
GOTO EOF
)
)
ENDLOCAL
)
Further Reading and Resources