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

  • Home
  • SEARCH
  • 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 8629503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:49:27+00:00 2026-06-12T08:49:27+00:00

My aim: Use Windows batch script to ensure that all files within given directory

  • 0

My aim: Use Windows batch script to ensure that all files within given directory and subdirectories have a file extension that is lowercase

I have managed to get this far (not very far I admit !)..

for /R c:\test %%G in (*.*) do (
  echo %%G
)

this successfully prints out all files with an extension (inc full path) but how do I check the file extension and ensure it is lowercase (I do not want to make the filename lowercase by the way .. just the extension).

Thanks in advance !

Greg

  • 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-12T08:49:28+00:00Added an answer on June 12, 2026 at 8:49 am

    There are 2 (possibly 3) techniques you need to accomplish your task.

    1) You need to parse out the file name and file extension – that is trivial as described in the FOR HELP. (type HELP FOR from the command line)

    • %%~nG = file name
    • %%~xG = file extension

    2) You need to store each file extension in a variable and then use code like the following to convert it to lowercase

    for %%C in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do set "ext=!ext:%%C=%%C!"
    

    You will need to enable delayed expansion with setlocal enableDelayedExpansion at the top of the script.

    The above works because the search portion of search and replace is case insensitive.

    3) In the unlikely situation that a file extension might containn a !, you need to toggle delayed expansion on and off within the loop. But I seriously doubt you will run into that situation.

    Here is a finished, functioning script that disregards point 3.

    @echo off
    setlocal enableDelayedExpansion
    for /r "c:\test" %%F in (*) do if "%%~xF" neq "" (
      set "ext=%%~xF"
      for %%C in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do set "ext=!ext:%%C=%%C!"
      ren "%%F" "%%~nF!ext!"
    )
    

    Bali C had an interesting idea in his answer, but it did not quite work. I managed to make it work by creating a temporary file with a name consisting only of the file extension in a temporary folder. But it is slower than the above solution.

    @echo off
    setlocal
    set "folder=%temp%\ren%random%"
    md "%folder%"
    for /r "c:\test" %%F in (*) do if "%%~xF" neq "" (
      copy nul "%folder%\%%~xF" >nul
      for /f "delims=" %%X in ('dir /b /l "%folder%"') do ren "%%F" "%%~nF%%X"
      del /q "%folder%"
    )
    rd "%folder%"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The eventual aim of this is to have a splash screen in windows that
Hi I have following JavaScript code that I am trying to run. My aim
Suppose I want to copy a file from a Windows local directory (not on
I am trying to use multimaps in C++. The main aim is that there
I aim to have a list of lines where I use the word NB
My project is to implement minimum spanning tree using java. I aim to use
basically my aim is to use JQuery to post back an x & y
AIM: I would like to tail the last line of the file.txt and input
AIM: To output the contents of a log file line by line newest at
Aim The aim is to a have a container DIV with a fixed height

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.