The ability to rename multiple files and folders in a specific folder is essential when working on web projects or apps. I often find myself needing scripts to lowercase and sanitize file names especially when working on Android projects. To save time, instead of writing the command lines out each and every time I created this blog post where I can collect handy lines of scripts that I can run in Windows Command Prompt or Windows Power Shell.

To be honest I find Windows power shell command lines easier and since it ships with Windows you can just use that out of the box no problemo. You might find that my Windows Power Shell command collection will grow faster. But I am happy to include command lines that you guys add to the comment section once I have vetted the code.

Windows Scripts to lowercase and rename file and folder names

Windows Power Shell – commands to rename files

To start Windows Power Shell just hit the “Windows” button and start typing “power shell” and hit return. Then use “cd”

// ========================
// Windows POWER SHELL commands
// ========================

//-------------------------------------- 
// 1. Rename All File Names in the CURRENT folder
//--------------------------------------

// 1.1 Make  all files Lower case
Dir | Rename-Item –NewName { $_.name.ToLower() }

// 1.2 Make  all files Upper case
Dir | Rename-Item –NewName { $_.name.ToUpper() }

// 1.3 Replace space " " with "_"
Dir | Rename-Item –NewName { $_.name –replace " ","_" }

// 1.4 Remove all special characters, leave alpha numeric only 
// and treat "." as an exception for file extension
Dir | Rename-Item -NewName { $_.name -replace "[^a-zA-Z0-9/.]" ,"" }

//-------------------------------------- 
// 2. Rename All File Names recursively the current and ALL Subfolders as well
//--------------------------------------

// 2.1 Recursive Replace space " " with "_" for ALL files
Get-ChildItem -Recurse -File | Rename-Item -NewName { $_.Name.replace(" ","_") }

// 2.2 Recursive Replace space " " with "_" for .txt files only
Get-ChildItem -Recurse -Include *.txt* | Rename-Item -NewName { $_.Name.replace(" ","_") }

Windows CMD – commands to rename files

To start Windows CMD just hit the “Windows” button and start typing “cmd” and hit return.

// ========================
// COMMAND LINE - CMD
// ========================

Change all file names in a folder:
---------------------------------

// Make all files lowercase
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")


Please note, the commend section may or may not have useful scripts OR it may even have MALICIOUS scripts. For your safety please only use the lines of code above. Once someone suggests a line of command and I have vetted it I will add it to the collection and mention the contributor.

I did not try this however if you need more complicated file renaming operations you could Renamer from space tornado.

Cheers!