65
38
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)
65
38
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)
128
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 for attribute
, -
stands for not
and d
stands for directory
).rename "%f" "%f"
- rename the file with its own name, which is actually lowercased by the dir
command and /l
combination.2Can it be modified to change lowercase to uppercase? – Chucky – 2016-01-07T16:52:51.637
This will fail if a file name begins with a space or semicolon. Better to use "eol=: delims="
– dbenham – 2016-07-21T21:15:04.380
1I had to change %f
to %%f
; then it worked just perfectly. – gilu – 2017-05-11T05:34:51.463
1For 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"))
– halexh – 2018-01-26T13:05:39.343
And how do i modify this code to change from uppercase to lower? – Rishav – 2018-02-18T03:41:39.000
This didn't work for me. In fact, rename FILE.EXT file.ext
doesn't work. – Seppo Enarvi – 2018-04-02T09:39:49.093
7Recursive version: for /f "Tokens=*" %f in ('dir /l/b/a-d/s') do (rename "%f" "%f")
(added /r to dir). – Sawny – 2013-02-13T18:20:55.150
3this is just briliant – Shir Gans – 2013-04-04T18:27:12.943
4The recursive version didn't work for me -- rename complained about the command being in an invalid format. Turns out the /s caused the second file to be listed as an absolute path and using filename expansion (%~nxf) gave me the original, uppercase filename. Ended up just manually recursing. – Dogmatixed – 2013-08-07T01:21:19.337
3This is a very nice answer; to the point, no external programs needed, nice and small command, no batch file complicated-ness needed. – Jeff Wilbert – 2013-10-10T15:44:59.190
18
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
I just upvoted you to cancel the downvote. Take THAT, downvoter! – Alan B – 2015-06-05T13:55:53.170
1It 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 :) – Nelson – 2015-10-12T09:28:26.740
The GUI is a little funky but it does the job better than several other renamers that I've seen out there. – jcollum – 2010-11-23T21:46:03.757
1Please give me the reason for down vote ? – joe – 2009-11-04T08:52:58.987
5People rarely explain, unfortunately :/ – Gnoupi – 2009-11-04T09:02:54.240
7I 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. – innaM – 2009-11-04T12:20:18.497
12
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} |
9
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
1Works great. FYI remove the /a-d
switch and it will also lowercase the folder names too. – Keith – 2017-07-18T14:50:10.293
Tried 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. – Don Cullen – 2018-04-12T17:49:10.747
1@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. – dbenham – 2018-04-12T18:22:49.317
Always learning something new everyday. Thanks! – Don Cullen – 2018-04-12T21:29:55.537
This worked for me in Command Line. Idk why it didn't work in PowerShell – OG Sean – 2019-11-24T22:43:59.590
6
My personal favorite batch file-renaming utility is Cylog's WildRename. Among many other features, it can change the case of filenames. The best thing about WildRename is probably that it supports regular-expressions!
THIS is the right app, after installation in 10 secs. I configured and renamed recursively a remote folder (mapped for convenience). – Matteo Conta – 2019-01-24T08:54:46.113
5
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"))
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
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).
Why do you have cmd /c "echo %cd%&
in the first for
? It is completely unnecessary. – DavidPostill – 2016-05-06T17:05:15.280
@DavidPostill echo %cd%
is there to add the current folder to the list of absolute paths; and cmd /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! – wc.matteo – 2016-05-07T11:19:26.163
Excellent 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.
– dbenham – 2016-07-21T22:13:55.780Can this be modifies to convert lower to caps? – Rishav – 2018-02-18T04:08:21.363
3
You could use a "character replacement" strategy...
set Name=%Name:A=a%
set Name=%Name:B=b%
set Name=%Name:C=c%
...and so on, for letters A-Z. You could probably implement it in the form of a FOR loop.
1
The accepted answer to this question, by loftysnake,
works for the current directory but does not search subfolders.
Sawny suggested a simple modification to loftysnake’s answer
to make it recursive, but it doesn’t work,
because, while the rename
command
allows you to specify a drive and path with filename1 (the source),
filename2 (the destination) must be just a filename.
To quote the help (/?
) message,
… you cannot specify a new drive or path for your destination file.
But move
works where rename
does not,
so you can recursively rename files to lowercase with this command:
for /f "Tokens=*" %f in ('dir /l/b/a-d/s') do (move /y "%f" "%f")
because it turns out that Move
can cope with directory paths.
The above command works
when typed directly into the Command Prompt (CMD.EXE
).
If you want to do this from within a batch (.BAT
) file,
you must double the %
characters:
for /f "Tokens=*" %%f in ('dir /l/b/a-d/s') do (move /y "%%f" "%%f")
And you can probably leave off the parentheses and the /y
and say just do move …
.
If 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). – Scott – 2017-05-30T17:09:57.017
Sorry, but I was pointing out that move
worked where rename
does not, and I think I am the only one who has suggested the use of the move
command here. I simply took @loftysnake and @sawny s suggestions, and hopefully improved them a wee bit. – Adrian – 2017-05-30T18:09:56.063
That’s weird; I thought somebody else had mentioned move
, but I can’t find it now. – Scott – 2017-05-30T19:13:53.543
1
The best program for doing this in Windows is Bulk Rename Utility. It is a mans tool. You can even use regex to rename files and/or folders. It also has shell integration (so you can execute from explorer with a right click) which is very nice. 64 bit and 32 bit versions available.
1
http://www.dostips.com/DtCodeCmdLib.php#Function.toLower gives a simple function that you should be able to include and call from a batch file.
So have the batch file iterate over the folders/filenames, and call this function to generate the lowercase version of the name.
1
From http://windowsitpro.com/articles/index.cfm?articleid=81612:
Using only standard commands, I have scripted LwrCase.bat and LwrCase_Folder.bat, to rename a file name to lower case, or rename all file names in a folder to lower case.
To rename a file name to lower case, use:
[call] LwrCase FullyQualifiedFileName
Where FullyQualifiedFileName is the fully qualified file name to be renamed.
To rename all the files names in a directory, use:
[call] LwrCase_Folder FullyQualifiedDirectoryName [/S]
where FullyQualifiedDirectoryName is the fully qualify folder path, and /S is an optional parameter that will also rename files names in all sub-folders.
NOTE: LwrCase.bat makes use the the /L switch of the DIR command, which returns lower case names.
LwrCase.bat contains:
@echo off
if {%1}=={} @echo Syntax: LwrCase FullyQualifiedFileName&goto :EOF
if not exist %1 @echo LwrCase - %1 NOT found.&goto :EOF
setlocal
for /f "Tokens=*" %%a in ('@echo %~a1') do (
set file=%%a
)
if /i "%file:~0,1%" EQU "d" @echo LwrCase - %1 is NOT a file.&endlocal&goto :EOF
for /f "Tokens=*" %%f in ('dir %1 /L /b /a /a-d') do (
Rename %1 "%%f"
)
endlocal
LwrCase_Folder.bat contains:
@echo off
if {%1}=={} @echo Syntax: LwrCase_Folder FullyQualifiedDirectoryName&goto :EOF
if not exist %1 @echo LwrCase_Folder - %1 NOT found.&goto :EOF
setlocal
for /f "Tokens=*" %%a in ('@echo %~a1') do (
set folder=%%a
)
if /i "%folder:~0,1%" NEQ "d" @echo LwrCase_Folder - %1 is NOT a folder.&endlocal&goto :EOF
pushd %1
set sw=/B /A /A-D
if /i {%2}=={/S} set sw=%sw% %2
for /f "Tokens=*" %%f in ('dir %sw%') do (
call LwrCase "%%f"
)
popd
endlocal
0
Powershell
Navigate to the dir and run:
dir | Rename-Item -NewName { $_.Name.ToLowerInvariant() }
I have verified that this works. Found here: http://www.hanselman.com/blog/PennyPinchingVideoMovingMyWebsitesImagesToTheAzureCDNAndUsingACustomDomain.aspx
0
Recursive solution. Put this into a recursiverename.cmd file..
for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f")
for /r /d %%x in (*) do (
pushd "%%x"
for /f "Tokens=*" %%f in ('dir /l/b/a-d') do (rename "%%f" "%%f")
popd
)
One 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. – Alan B – 2015-06-05T13:54:44.477
10I know this is old, but I wanted to clarify a misconception here. While NTFS supports case sensitivity, the Windows OS DOES NOT differentiate! – geo – 2013-01-23T20:37:40.407
windows 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. – Rook – 2009-11-04T00:47:17.953
1
@Idigas. Sorry, but since NTFS, filenames have been case sensitive. See http://support.microsoft.com/kb/100625
– DaveParillo – 2009-11-04T06:49:20.080Just 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'. – David – 2009-11-04T12:45:46.807
2@David, for example Java actually requires case-sensitive file names. That can yield a lot of trouble on non-case-sensitive file systems. – Arjan – 2009-11-04T17:26:42.740