Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:41:06+00:00 2026-06-02T23:41:06+00:00

how can i batch rename the files from folder A which contains subfolders and

  • 0

how can i batch rename the files from folder A which contains subfolders and files with this format name filename_ex.doc and make them look like filename.doc?

i’ve been trying to do this for awhile now and it’s been an epic fail. please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:41:07+00:00Added an answer on June 2, 2026 at 11:41 pm

    I presume you want to rename the files in the subfolders as well, which is where you had problems with the direction in your 2nd comment to Martin James. I’m guessing you tried that code with the DIR /S option. But you were so close 🙂 You just needed to use 2 loops!

    Edit – fixed code Once the output looks correct, drop the ECHO to make it functional.

    @echo off
    for /r %%D in (.) do (
      pushd "%%~fD"
      for /f "tokens=1-3 delims=_." %%A in ('dir /b *_ex.ext 2^>nul') do echo ren "%%A_%%B.%%C" "%%A.%%C"
      popd
    )
    

    The above will work as long as each file name does not have any _ or . other than what appears in _ex.ext. Characters in the path should not be any problem, just the file name is a concern.

    Here is a more robust solution that should work with any filename (except unicode names). It is also significantly faster. It uses a substring operation, and you must know the number of characters to strip from the name. In your example it is 3 characters. Again, remove ECHO once the resultant commands look correct.

    @echo off
    setlocal disableDelayedExpansion
    for /f "delims=" %%F in ('dir /b /s *_ex.ext') do (
      set "old=%%F"
      set "new=%%~nF"
      setlocal enableDelayedExpansion
      echo ren "!old!" "!new:~0,-3!.ext"
      endlocal
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can make batch or vbs file on windows and run. this can automate
I would like to batch copy and rename all files from a directory, recursively.
How can I make a batch file wait until another batch file has finished?
How can you you insert a newline from your batch file output? I want
here i need a batch file which can apply and create label or base
I have a directory which contains files and a number of levels of subdirectories:
PowerShell can call commandline batch files. PowerShell script output can be recorded with the
I have searched high and low for a way to batch rename files in
Do you know a tool that can accomplish this? or some dirty batch command
Can a Windows batch file determine its own file name? For example, if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.