Tag Archives: Rename

PowerShell – Reverse strings and reverse file names

With PowerShell it is relatively easy to reverse a string:
$str = “gnirtsdesrever”
$str[-1..-($str.length)] -join “”

Some of you might ask: Why would anyone want to do this ? Well, since the start of the year Usenet DMCA takedowns have begun to occur automatically, very quickly and very often. This means many movies and TV series on Usenet / News Groups are being taken offline very quickly.

Counter measures to prevent takedowns by uploaders include:

  • The use of encrypted links to NZB files.
  • The use file names that make it harder to find copyrighted files.

As you can probably guess, some just reverse the file names. The PowerShell script I’ve created will automate reversing the file names for files in the specified folder that match the specified file name filter.

I hope it is useful for you as well.

PS: Someone else on usenet had the same idea as me and created a VBS that will add a right-click menu option to explorer. I’ve added this in the same location as my PowerShell script as well.


Tags: , , , , , , ,

Easily rename downloaded movies using powershell


As most people, I often complain about not having sufficient time. It also doesn’t help that I have a lot of hobbies and interests. Because of this I decided to combine my hobbies and interests in such a way it would eventually save me time.

Basically I decided to learn powershell scripting by automating the task of renaming downloaded movies. These need to be in a specific format for reliable use with the movie jukebox called Yet Another Movie Jukebox (YAMJ). As a result this will save me a lot of time in the future.

Concept for the script

The file names of most movies I download are mostly in the following format:
<>.<movie release year>.<metadata>.<metadata>…..<last.metadata>.<file extension>

What is important for YAMJ to work correctly is basically the movie name and the year (just in case there are movies with the same name, but released in a different year). So basically my preferred output would be:
The Devils Advocate 1997.mkv

To realise this, conceptually the following will be done for all files in a specific folder:

  1. Determine the current file extension and save it to a variable.
  2. Remove all dots “.” from the file name.
  3. Determine if there is a year notation in the file name (by example 1997).
  4. If there is no year notation found, don’t do anything else (file does not meet the expected format).
  5. If the year notation is found, remove everything from the file name after the year notation and re-add the file extension.

The script itself

The script itself can be found on my sharepoint list :

Closing thoughts

I hope this will help home users to see the advantages of scripts, use them and benefit from it. For ICT professionals I also hope that it will help them get a better understanding of Powershell. Because in my opinion Powershell is getting increasingly important both for Microsoft and non Microsoft products (by example VMware).

I’d love to get feedback about this post and hope to receive some replies.


Tags: , , , , , , , , , , ,

%d bloggers like this: