NicolTIP#010: How to rename and manage file names of your video (and audio?) library with powershell on Windows 7:-)


This week end I encoded some my old DVD in wmv file because I’m destroying my old DVD player and I don’t want to buy a blue ray disk (I’m sorry Sony:-).

After the encoding arrived the boring time to organize file names, and because now PowerShell is available to everyone OOB with Windows 7, this sounds like a good opportunity for me to test my skills in that area.

(these tricks can be usable and useful even if you download series from torrent & co. but because it seems something not so legal, please do not ping me about this topic:-)

 

Well, lets’ start with a list of files:

 

PS C:\TEMP\temp> dir


    Directory: C:\TEMP\temp


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         20-Jan-10   3:49 PM          0 Ephisode 1.wmv
-a---         20-Jan-10   3:49 PM          0 Ephisode 2.wmv
-a---         20-Jan-10   3:49 PM          0 Ephisode 3.wmv
-a---         20-Jan-10   3:49 PM          0 Ephisode 4.wmv

 

Let add series information at begin of the file name:

 

PS C:\TEMP\temp> dir | %{$x=1} {rename-item $_ -NewName "E1-$x Scrubs -.wmv"; $x++}
PS C:\TEMP\temp> dir


    Directory: C:\TEMP\temp


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         20-Jan-10   3:49 PM          0 E1-1 Scrubs -.wmv
-a---         20-Jan-10   3:49 PM          0 E1-2 Scrubs -.wmv
-a---         20-Jan-10   3:49 PM          0 E1-3 Scrubs -.wmv
-a---         20-Jan-10   3:49 PM          0 E1-4 Scrubs -.wmv

Ok, now I have a file with all ep. titles:

My first day
My Mentor
My Best Friend's Mistake
My Old Lady

 

And with the following rows I add the title to the file name:

PS C:\TEMP\temp> $title = Get-Content "..\titles.txt"
PS C:\TEMP\temp> dir | %{$x=0} {rename-item $_ -newname ("E1-" + ($x+1) + " Scrubs - " + $Title[$x] + ".wmv"); $x++ }
PS C:\TEMP\temp> dir


    Directory: C:\TEMP\temp


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         20-Jan-10   3:49 PM          0 E1-1 Scrubs - My first day.wmv
-a---         20-Jan-10   3:49 PM          0 E1-2 Scrubs - My Mentor.wmv
-a---         20-Jan-10   3:49 PM          0 E1-3 Scrubs - My Best Friend's Mistake.wmv
-a---         20-Jan-10   3:49 PM          0 E1-4 Scrubs - My Old Lady.wmv

 

and now let’s add something at the end:

PS C:\TEMP\temp> foreach ($f in dir) {rename-item $f -newname ($f.Name.Replace(".wmv", "- ripped by Nicold.wmv"))}
PS C:\TEMP\temp> dir


    Directory: C:\TEMP\temp


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         20-Jan-10   3:49 PM          0 E1-1 Scrubs - My first day- ripped by Nicold.wmv
-a---         20-Jan-10   3:49 PM          0 E1-2 Scrubs - My Mentor- ripped by Nicold.wmv
-a---         20-Jan-10   3:49 PM          0 E1-3 Scrubs - My Best Friend's Mistake- ripped by Nicold.wmv
-a---         20-Jan-10   3:49 PM          0 E1-4 Scrubs - My Old Lady- ripped by Nicold.wmv

 

enjoy!

 

PS. Yes I love Scrubs🙂

Comments (2)

  1. Garry Trinder says:

    um… Since you’re file’s new name is based on it’s position is the dir stream, as opposed to it’s original title, youmight want to put an sort in there…

  2. NicolD says:

    If the files have square brackets:

    foreach ($f in dir) {move-item -literalpath $f ($f.Name.Replace(".wmv", "- ripped by Nicold.wmv"))}

Skip to main content