i found out about Powershell renaming some years ago by trying to remove the "-eng" part at the end of .srt files for tv series. Found this command which has been working perfectly when i needed to rename dozens of files.
get-childitem *.srt | foreach {rename-item $_ $_.name.replace("-eng","")}
This is the only command i know of. I just know nothing about powershell nor coding at all. Now for example i have these files.
- Sword Art Online II - 01 [BD][FS].mp4
- Sword Art Online II - 02 [BD][FS].mp4
24 of them. The idea is to get this result
- 02 - 01.mp4
- 02 - 02.mp4
etc.
So i need to replace.
Sword Art Online II --> 02
and
[BD][FS] --> ""
Thought it wouldnt be that hard. But im getting erros. For example i tried
get-childitem *.mp4 | foreach {rename-item $_ $_.name.replace("Sword Art Online II ","")}
But i get this error
rename-item : Cannot rename because item at 'C:\users\santo\downloads\02\Sword Art Online II - 01 [BD][FS].mp4' does
not exist.
At line:1 char:32
+ ... | foreach {rename-item $_ $_.name.replace("Sword Art Online II ","") ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand
So i tried with the last part but i get the exact same error
rename-item : Cannot rename because item at 'C:\users\santo\downloads\02\Sword Art Online II - 01 [BD][FS].mp4' does not exist.
At line:1 char:32
+ ... item *.mp4 | foreach {rename-item $_ $_.name.replace(" [BD][FS]","")}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand
I believe i am in the correct directory cause i enter dir command and it lists all 24 files by using "cd " and "cd.." Using Windows Powershell (admin) Tried looking for the error line. What does this mean " PSInvalidOperationException " I just dont know what im getting into.
What am i doing wrong? Any thoughts?