Make every file in a Directory Structure Lowercase (Windows)

6

3

I have a legacy directory structure from a desktop application that I'm porting to an Android application, and Android doesn't want the names of the files to have capital letters in them. I had originally decided to suck it up and rename them by hand (about a hundred files), but then I found that Windows was thwarting even those attempts: QuotationMarks.png -> quotationmarks.png doesn't even stick, because Windows is case-insensitive: it doesn't even register it is as a filename change. I'd have to QuotationMarks.png -> quotationmarks2.png -> quotationmarks.png for all files, which I would like to avoid.

So is there some kind of secret power app that will allow to perform this operation batch?

C. Warren Dale

Posted 2013-05-25T20:39:56.677

Reputation: 63

Keltari's script does the job no doubt, but I can't even begin to count the number of bulk file renamers available for Windows. Any one of them would have helped I'm sure. – Karan – 2013-05-25T22:12:42.993

The key is the method of renaming. Renaming the file to all lowercase will fail in some cases, since Windows isnt case sensitive and the file already exists as that name. If you change my script to rename the file, it will fail saying the file already exists. Thats why I used the MoveFile function. However, if you had Services for Unix installed, renaming should work... – Keltari – 2013-05-26T01:57:13.890

Answers

9

Command line:

for /F %a in ('dir /L /B') do ren %a %a

batch:

for /F %%a in ('dir /L /B') do rename %%a %%a

STTR

Posted 2013-05-25T20:39:56.677

Reputation: 6 180

in case the filenames have whitespace, add quotes in rename: for /F %a in ('dir /L /B') do ren "%a" "%a", see also https://superuser.com/questions/65302/is-there-a-way-to-batch-rename-files-to-lowercase

– Pedi T. – 2017-09-13T11:57:16.243

This works too. – Keltari – 2013-05-26T03:02:08.347

This one gets the pot for conciseness. Nice job! – C. Warren Dale – 2013-05-28T16:53:14.003

3

This VBScript will do it. Be sure to set the variable objStartFolder to the right location. Save as a .VBS and double click to run. It will rename all the files in the specified directory to all lower case.

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Myfolder"

Set objFolder = objFSO.GetFolder(objStartFolder)

Set colFiles = objFolder.Files
For Each objFile in colFiles
    ObjFSO.MoveFile objStartFolder & "\" & ObjFile.Name, objStartFolder & "\" & lcase(ObjFile.Name)
Next

PS. Technically, I am not renaming the file, but moving it, but the results are the same. Renaming the file will fail, since the filename already exists.

Keltari

Posted 2013-05-25T20:39:56.677

Reputation: 57 019

Thanks! I ended up booting into Linux and writing a shell script, but you deserve recognition for your answer! Thank you! – C. Warren Dale – 2013-05-25T21:39:14.917

Just curious - any particular reason why you deleted the almost identical answer, then posted this one a minute later? – Karan – 2013-05-25T22:11:04.333

@Karan I was editing the answer, or was attempting to, hit the backspace key which instead of deleting the character took me back a page. I ended up editing the answer there and committing the change, but it made a new answer. – Keltari – 2013-05-26T01:50:52.967