rename
or ren
command in a Command Prompt window to one or more files. The command accepts wildcard characters like * and ? for matching multiple files, which can be helpful if you only want to rename a certain selection of files in a folder full of many.ren
command can address extensions, you can also use it to change the extensions of multiple files at once. Say, for example, you had a selection of .txt files that you wanted to turn into .html files. You could use the following command along with the * wildcard (which basically tells Windows that text of any length should be considered a match):Dir
, which lists the files in the current directory, and Rename-Item
, which renames an item (a file, in this case). Pipe the output of Dir to Rename-Item and you’re in business.rename-item
commandlet. Say, for example, we had a bunch of files named “wordfile (1).docx”, “wordfile (2).docx”, and so on.dir
part of that commandlet lists all the files in the folder and pipes them (that’s the |
symbol) to the rename-item
commandlet. The $_.name
part stands in for each of the files getting piped. The -replace
switch indicates that a replacement is going to happen. The rest of the commandlet just signifies that any space ( ' '
) should be replaced by an underscore ( '_'
).rename-item
commandlet also offers features like a -recurse
switch that can apply the commandlet to files in a folder and all folders nested inside that folder, a -force
switch that can force renaming for files that are locked or otherwise unavailable, and even a -whatif
switch that describes what would happen if the commandlet was executed (without actually executing it). And, of course, you can also build more complicated commandlet structures that even include IF/THEN
logic. You can learn more about PowerShell in general from our Geek School guide, and learn more about the rename-item
commandlet from Microsoft’s TechNet Library.