I have almost no powershell experience but was using it as a means to an end to replace possibly problematic characters in FAT32 filenames, such as: , . / ' : etc.
I discovered an article positing use of rename-item -NewName command, whichs works fine inside a specific directory containing files meeting said criteria, but when used at a level above this, I can't figure out how to make the script fully recursive.
I want to replace spaces, apostrophes, instances of periods outside of file extensions, and dollar signs in filenames of audio tracks inside a music library folder that's laid out like so**, running powershell script from music folder to hit everything inside and below that:
X:\home\audio\**music**\[artist_here]\[album_here]\FILE.mp3
Can someone explain the correct syntax to accomplish this?
I also tried using path and /s:
dir X\pathnamehere\ /s | rename-item -NewName {$_.name -replace " ","_"}
but receive another error:
dir : Second path fragment must not be a drive or UNC name.
Parameter name: path2
At line:1 char:1
+ dir X:\home\Audio\Music\ /s | rename-item -NewName {$_.name -repla ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (X:\home\Audio\Music:String)
[Get-ChildItem], ArgumentException
+ FullyQualifiedErrorId :
DirArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand
dir | rename-item -NewName {$_.name -replace " ","_"}
when running
dir | rename-item -NewName {$_.name -replace " ","_"}
at multiple levels above where files to be renamed are located, I receive the following error for EVERY directory inside \music:
"rename-item : Source and destination path must be different."
+ dir | rename-item -NewName {$_.name -replace " ","_"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError:
(X:\home\Audio\Music\artistname:String) [Rename-Item], IOException
+ FullyQualifiedErrorId :
RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand
Thank you!
P.S. if this can be accomplished with a simpler command prompt batch file, feel free to enlighten me.