Rename certain files within a folder

Maikel 6 Reputation points
2022-02-21T13:36:21.35+00:00

Hello, i want a Batch that finds Files in a Folder that are called master_example. After they found all of them, they should rename ONLY the part "master" into a specific string of numbers (example:657432).
How can i do that?

Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 13,376 Reputation points Microsoft Employee Moderator
    2022-02-21T18:35:10.18+00:00

    Hello @Maikel ,
    Can you try out the below script:

    **Start of script **
    setlocal enableDelayedExpansion
    for %%F in (master*.txt) do (
    set "name=%%F"
    ren "!name!" "!name:master=123456!"
    )

    **End of Script **

    Explanation of the script
    Line No1:- Why to use enableDelayedExpansion :- https://ss64.com/nt/delayedexpansion.html
    Line No4:- How the rename command works with regular expressions :- https://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards

    **End of Explanation of the script **

    I just tested it locally:

    176494-image.png

    176562-image.png

    Regards,
    Shiva


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.