Windows PowerShell is a Microsoft framework for automating tasks using a command line shell.
In this tutorial we will learn on how to change a file name or its extension using either the relative directory or absolute directory.
Here is a short 3 minute video in which I walk through how to change a file name or its extension.
We will be using Rename-Item cmdlet. You can read more in the official docs here.
Using Rename-Item
we can not only rename a file but also move it into different directories or even change registry names as well.
You can find some very good official examples on the PowerShell docs page here.
So let's begin.
How to rename a file
Open your PowerShell command line shell. Type in the following command:
Rename-Item -LiteralPath "hello.xls" -NewName "bye.xls"
Rename-Item accepts two flags:
- LiteralPath is the file you want to rename
- NewName is the new name of the file you want
How to change a file extension
You can change the extension of a file similar to how you would rename it by simply doing this:
Rename-Item -LiteralPath "hello.txt" -NewName "hello.docx"
If you found this useful drop a message to me on twitter/adeelibr.
Happy coding.
Top comments (0)