Bulk MP3 extension rename .~#T0

I’ve got an MP3 folder that apparently got stuck in a half state for archiving with an HP product some time ago.

So, some artists folders got renamed “~HpShadow” and then the mp3 files themselves got the extension renamed to .~#T0

I was hoping PS could help me find and rename these. (The Folder rename isn’t necessary because the album name wouldn’t be known, I’d have to do after a bit of research). But since the song titles are intact, I simply need to bulk rename the extensions to “mp3” and I believe that’ll be good.

I have this so far:

$Dir = Get-ChildItem -dir F:\MP3s -Recurse < — works
$List = $Dir | where {$_.extension -eq ".~#T0"} < ---- error
$list | ft name < ---- just wanted to see a list of the files and location

…but I'm not getting any results from my where statement. When I pipe Get-ChildItem -dir F:\MP3s -Recurse to gm I don't see Extension as a property. Moreover, I'm getting an errro about illegal character. Which one, the tilde?

How can I find the files and rename them?

The problem is going to be that you are using the -dir parameter with Get-ChildItem, which tells Get-ChildItem to only return directories, not files. Directories, of course, do not have extensions.

Gets directories (folders). 

To get only directories, use the Directory parameter and omit the File parameter. To exclude directories, use the File parameter and omit the Directory parameter, or use the Attributes parameter.

To get directories, use the Directory parameter, its "ad" alias, or the Directory attribute of the Attributes parameter.
$files = Get-ChildItem -Path .\path\to\files -Filter '*.~#T0' -Recurse
"$($files.Count) files found"
$files.DirectoryName | Out-File .\path\to\files\parentlog.txt -Append
$files | Rename-Item -NewName {$_.Name -replace '.~#T0','.mp3'} -whatif


How come neither the -dir nor the -file parameters are listed in the get-help get-childItem -Full help file?


The -dir and -file switches were introduced in v3. Are you running v3 or later? Have you updated your help files?

v4 but I can’t update AD and GP modules for some reason. I do have an access denied issue open with MS on this very subject and also soliciting help from this forum: https://powershell.org/forums/topic/update-help-access-denied-on-domain-controller/

@jeff-taylor, in addition to Bob’s reply, Get-ChildItem is used by much more than just a file system. It can work with other providers, such as the Registry, which does not support -directory and -file

Here is a link to “Get-ChildItem for FileSystem”

random commanline thanks -whatif works great. How would I measure the number of files discovered/changed?

I tried:
Get-ChildItem -Path F:\MP3s -Filter ‘*.~#T0’ -Recurse | Rename-Item -NewName {$_.Name -replace ‘.~#T0’,’.mp3’} -WhatIf | measure

returns value = 0

…and also, how can I log the returned parent folders which contain these files? I’ll have to change the name from ~HPShadow to the album name after some analysis.

thanks again

Try it again. I modified my script to display number of files found and output parent folders to a log file.

random commandline Thanks a lot…Worked a charm and I learned a lot in the process…Cheers