Is there a way to batch rename files to lowercase?
Solution 1
Go to the directory and run the following command:
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
Here is the break-down in case someone wants to modify/improve :
-
for /f
- For every line -
"Tokens=*"
- Process each item in every line. -
%f in (...)
-%f
is your variable name for every item. -
dir
- lists every file and subdirectory in a directory. -
/l
- (parameter for dir) Uses lowercase. -
/b
- (parameter for dir) Uses bare format, only the file/directory names, no size, no headers. -
/a-d
- (parameter for dir) Do not list directories. (a
stands forattribute
,-
stands fornot
andd
stands fordirectory
). -
rename "%f" "%f"
- rename the file with its own name, which is actually lowercased by thedir
command and/l
combination.
Solution 2
Since Windows 7 you could use PowerShell for those tasks
Get-ChildItem "C:\path\to\folder" -recurse |
Where {-Not $_.PSIsContainer} |
Rename-Item -NewName {$_.FullName.ToLower()}
- Choose your root folder
- all files inside root folder and subfolders are renamed
- folder names are excluded with Where {-Not $_.PSIsContainer} |
Solution 3
spacetornado Renamer is a Windows program that renames mass amounts of files in batches. You can search and replace text, remove a certain number of characters, change the case to lower, upper or First Letter Capital, and add text to the beginning or end (append/prepend) of every filename
Solution 4
Here is a proper recursive command line solution using only native cmd.exe commands that actually works. I believe it is the simplest possible native solution:
for /r %D in (.) do @for /f "eol=: delims=" %F in ('dir /l/b/a-d "%D"') do @ren "%D\%F" "%F"
If you are willing to go beyond native cmd.exe commands, then another option is my JREN.BAT regular expression renaming utility that supports options to convert names to upper or lower case. It is pure script (hybrid JScript/batch) that runs natively on any Windows machine from XP onward - no 3rd party exe files needed. Full documentation is built in - accessed from the command line via jren /?
, or jren /??
if you want paged output.
With JREN, the recursive solution is as simple as:
jren "^" "" /s /l
Solution 5
"Recursive" version of the accepted answer (that works*)
for /f "Tokens=*" %f in ('cmd /c "echo %cd%& dir /l/b/ad/s"') do (for /f "Tokens=*" %g in ('dir /l/b/a-d "%f"') do (rename "%f"\"%g" "%g"))
The first loop
for /f "Tokens=*" %f in ('cmd /c "echo %cd%& dir /l/b/ad/s"')
Gets a list of the absolute paths of all the directories inside the current (including it):
C:\Foo>
C:\Foo\TO.txt
C:\Foo\Bar\LOWER.txt
C:\Foo\Bar\Baz\CASE.txt
The second loop
for /f "Tokens=*" %g in ('dir /l/b/a-d "%f"') do (rename "%f"\"%g" "%g")
Gets a list of all the file names (or file and directory names if you take out the /a-d
switch) inside each of the absolute paths found by the first loop, and converts the name of these files to lowercase.
C:\Foo\TO.txt
C:\Foo\Bar\LOWER.txt
C:\Foo\Bar\Baz\CASE.txt
* it needs two loops because the second argument to rename
must be a file name and not an absolute path (as the one obtained by the /s
switch).
Related videos on Youtube
Comments
-
ino almost 2 years
I need a way to rename all files in folders and subfolders to lowercase.
I'd like to know if there is a way to do that using only windows (XP or 7)
-
Admin over 14 yearswindows doesn't differentiate between small and upper caps as unix does. maybe, if you said, why you need this, it would help in solving the problem.
-
Admin over 14 years@Idigas. Sorry, but since NTFS, filenames have been case sensitive. See support.microsoft.com/kb/100625
-
Admin over 14 yearsJust great. Take a bad idea and spread it further. What a support nightmare when someone sends a file and a fat finger mistake means they sent "Answers.dat" and the incoming process expects "answers.dat". There's just no good reason for those two names to be considered 'different'.
-
Admin over 14 years@David, for example Java actually requires case-sensitive file names. That can yield a lot of trouble on non-case-sensitive file systems.
-
Admin about 9 yearsOne reason as pointed out is cross-platform tools like Java. For example, if you're serving PDF downloads from an Apache web server on Windows, you need to respect the case of the disk filename.
-
-
joe over 14 yearsPlease give me the reason for down vote ?
-
Gnoupi over 14 yearsPeople rarely explain, unfortunately :/
-
innaM over 14 yearsI guess the downvote was because the OP wanted a solution that worked without any additional software. And I guess the downvote wasn't explained because some people are prone to deal out revenge downvotes.
-
jcollum over 13 yearsThe GUI is a little funky but it does the job better than several other renamers that I've seen out there.
-
Shir Gans about 11 yearsthis is just briliant
-
Jeff Wilbert over 10 yearsThis is a very nice answer; to the point, no external programs needed, nice and small command, no batch file complicated-ness needed.
-
Alan B about 9 yearsI just upvoted you to cancel the downvote. Take THAT, downvoter!
-
Nelson over 8 yearsIt did what it did, when I needed recursive renaming for cleaning up files from a Linux FTP server... however, needed to run it as Admin before it worked properly. Feels like an old an un-maintained program :)
-
Chucky over 8 yearsCan it be modified to change lowercase to uppercase?
-
DavidPostill about 8 yearsWhy do you have
cmd /c "echo %cd%&
in the firstfor
? It is completely unnecessary. -
wc.matteo about 8 years@DavidPostill
echo %cd%
is there to add the current folder to the list of absolute paths; andcmd /c
makes&
work to combine commands. I'm a total noob regarding Windows Batch Scripting; if you know of a better way, feel free to improve the answer! -
dbenham almost 8 yearsThis will fail if a file name begins with a space or semicolon. Better to use
"eol=: delims="
-
dbenham almost 8 yearsExcellent job for a noob. Yours was the first native cmd.exe command line solution that actualy works, except it fails when a name begins with space or semicolon.The accepted answer suffers the same problem. See my answer for a simpler answer that also works with leading space or semicolon.
-
gilu about 7 yearsI had to change
%f
to%%f
; then it worked just perfectly. -
Scott - Слава Україні about 7 yearsIf you're going to re-post information that others have already posted, you should identify the original author(s) and link to their post(s).
-
Adrian about 7 yearsSorry, but I was pointing out that
move
worked whererename
does not, and I think I am the only one who has suggested the use of themove
command here. I simply took @loftysnake and @sawny s suggestions, and hopefully improved them a wee bit. -
Scott - Слава Україні about 7 yearsThat’s weird; I thought somebody else had mentioned
move
, but I can’t find it now. -
Keith almost 7 yearsWorks great. FYI remove the
/a-d
switch and it will also lowercase the folder names too. -
halexh over 6 yearsFor recursive, I had to do the following to get it to work. I hade the same issue as @Dogmatixed.
for /f "Tokens=*" %g in ('dir /b') do (for /f "Tokens=*" %f in ('dir %~fg /l /b /a-d') do (rename "%~fg\%f" "%f"))
-
Rishav over 6 yearsAnd how do i modify this code to change from uppercase to lower?
-
Rishav over 6 yearsCan this be modifies to convert lower to caps?
-
Seppo Enarvi about 6 yearsThis didn't work for me. In fact,
rename FILE.EXT file.ext
doesn't work. -
Don Cullen about 6 yearsTried saving it as a batch file and popped it in system32 so I could run it anytime with a single command. Results in this:
" D"') was unexpected at this time.
Running it as a direct command works fine, just doesn't work when run as a batch file. Not sure as to how to make it work as a batch file, but thought I'd give heads up to the issue. -
dbenham about 6 years@DonCullen - It is standard syntax that FOR variable percents must be doubled when using FOR within a batch script. So
%D
must change to%%D
, and%F
to%%F
if you put the command within a batch script. -
Don Cullen about 6 yearsAlways learning something new everyday. Thanks!
-
Matteo Conta over 5 yearsTHIS is the right app, after installation in 10 secs. I configured and renamed recursively a remote folder (mapped for convenience).
-
OG Sean over 4 yearsThis worked for me in Command Line. Idk why it didn't work in PowerShell
-
Hugo Delsing over 4 yearsFirst one that actually worked. Thanks!
-
fedmich about 4 yearsThanks. worked on my windows 7
-
Deka87 almost 4 yearsThis software is a beast.
-
Tadej over 3 yearsThis worked for me:
for /f "Tokens=*" %%f in ('dir /l/b/a-d/s') do (rename "%%f" "%%f")
on Windows 10. -
Agile Jedi almost 3 yearsWon't work...Powershell doesn't allow renaming something to the same name...even if the case is different.
-
user2308001 over 2 yearsI can confirm that this does not currently work, it throws this error: Rename-Item : Source and destination path must be different.
-
Admin about 2 yearsAlthough Its working in windows-10-home
-
Admin about 2 yearsHow exactly do you run this command? Powershell doesn't understand it.