I am looking to rename all directories on a certain hard drive (not C:) by capitalising the first letter of every directory (so: \images -> \Images). Unfortunately I have not enough experience to write this from scratch.


The following native batch script will rename all directories in drive X:, ignoring read only, hidden, and system directories and ignoring reparse points. It converts the names to lower case and then capitalizes the initial character of the directory name (English characters). It does not handle unicode in names.

@echo off
setlocal disableDelayedExpansion
set "drive=x"
set "tempFile=%temp%\initUpper%random%.txt"
dir /s /b /l /ad-l-h-s-r %drive%:\* >"%tempFile%"
for /f "usebackq eol=: delims=" %%F in ("%tempFile%") do (
  set "old=%%F"
  set "new=%%~nxF"
  setlocal enableDelayedExpansion
  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 if /i "!new:~0,1!" equ "%%C" set "new=%%C!new:~1!"
  ren "!old!" "!new!" 2>nul || echo unable to rename !old!
del "%tempFile%"

The script uses a temp file for performance reasons. It could be modified to have FOR /F read the output of the DIR command directly. But the output can be quite large, and FOR /F becomes very slow if the command result set is very large.

There are many tweaks that can be applied to the DIR command. For example:

Remove the /ad option to rename files and directories: dir /s /b /l /a-l-h-s-r

Remove the /a-h-s options to include hidden and system folders: dir /s /b /l /ad-l-r

Remove the /l option to preserve case of all but initial character: dir /s /b /ad-l-h-s-r


As Martheen Cahya Paulo mentions in the comments, this question has already been answered, however indirectly.

You can use a great tool, Space Tornado Renamer, as posted here: https://superuser.com/a/65304/125301,

  • Yeah, any of the numerous free/paid mass renamers can do this easily. I'm sure it can be accomplished using a batch file as well, but if it's not absolutely necessary I would advise you to avoid them (especially when they get complicated and hard to maintain/update). – Karan Dec 24 '12 at 15:54
  • It's a great tool for files, but not for folders. – CustomX Oct 5 '14 at 11:59

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.