2

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.

  • Have You tryed Total Commander? It does have multiple rename tool - ghisler.com/screenshots/en/06.html – integratorIT Jan 21 '16 at 14:23
  • 1
    @GuessXYZ Questions seeking service recommendations or learning materials are off topic here plus similar questions already have an answer. Like this one here – pun Jan 21 '16 at 14:37
  • This can be done using FOR, SET and REN. If no answer has been given tonight, I'll write one then. (FOR is done to go through all the files, SET is done to create a new filename and replace %20 with _, and REN to do the actual renaming. – LPChip Jan 21 '16 at 14:43
  • Questions seeking product, service, or learning material recommendations are off-topic because they become outdated quickly and attract opinion-based answers. Instead, describe your situation and the specific problem you're trying to solve. Share your research. – Ƭᴇcʜιᴇ007 Jan 21 '16 at 14:45
  • I use ReNamer myself, and it supports replacement rules (as well as many many others), has (sortable) previewing capability, and just generally works the way I want. Also, thought it is unintuitive, I recommend you edit your post to simply ask how you might perform a batch rename. that way you are not asking for software/service/learning materials, even though your question is the same. Its kind of paradoxical, but thats the way they roll here. – Frank Thomas Jan 21 '16 at 14:47
0

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

  • To me, the OP didn't ask for a script to be written (which would be closed), they asked where they could learn to script (which is off-topic). – Ƭᴇcʜιᴇ007 Jan 21 '16 at 14:47
  • @Techie007 I would rather run a script than download a program if possible. – Pimp Juice IT Jan 21 '16 at 14:48
  • 1
    With my comment, I would explain how to use FOR, REN and SET so they can construct their own script and possibly give an example. I don't agree with @Ƭᴇcʜιᴇ007 with this view in mind, because as the question is currently written it is possible to answer it in regards to what SuperUser allows. You took some effort to help here even though the answer could have been formulated a bit more to what is allowed at SuperUser. For the effort I still give you a +1. This does not deserve a downvote. – LPChip Jan 21 '16 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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