Solved

Renaming multiple file extensions using Powershell

Posted on 2016-11-29
4
10 Views
Last Modified: 2016-11-29
Heyas,

How do rename all .csv files in a directory to .xls using PowerShell, preserving the filename of course?

I found this command: Get-ChildItem -Filter “*csv*” -Recurse | Rename-Item -NewName {$_.name -replace ‘csv’,’xls’ }

But I want to make sure only the file extension part of the file is changed.

Any assistance is appreciated.

Using powershell v3 on the server.

Thank you
0
Comment
Question by:Zack
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Malmensa
Comment Utility
From a boring old DOS prompt, REN *.csv *.xls will do that. Pretty sure this works in exactly the same way from within Powershell.
0
 

Author Comment

by:Zack
Comment Utility
Hi Malemsa,

I need a PowerShell version of this I am been tasked with modifying PowerShell job in Task Scheduler.

Thank you.
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
This is in test mode and will only display what it would do normally. Remove the "-WhatIf" at the end to run it for real.
Get-ChildItem -Filter "*.csv" -Recurse | % {Rename-Item -Path $_.FullName -NewName ($_.BaseName + '.xls') -WhatIf}

Open in new window

0
 

Author Closing Comment

by:Zack
Comment Utility
Thank you for your help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now