--- /usr/share/doc/mythtv-docs-0.21/contrib/mythrename.pl	2008-05-10 12:17:49.000000000 +0200
+++ /usr/local/bin/mythrename.pl	2008-05-18 16:53:43.000000000 +0200
@@ -22,7 +22,7 @@
     use MythTV;
 
 # Some variables we'll use here
-    our ($dest, $format, $usage, $underscores, $live);
+    our ($dest, $filename, $format, $usage, $underscores, $live);
     our ($dformat, $dseparator, $dreplacement, $separator, $replacement);
     our ($db_host, $db_user, $db_name, $db_pass, $video_dir, $verbose);
     our ($hostname, $dbh, $sh, $q, $count, $base_dir);
@@ -41,6 +41,7 @@
 
 # Load the cli options
     GetOptions('link|dest|destination|path:s' => \$dest,
+               'file:s'                       => \$filename,
                'format=s'                     => \$format,
                'live'                         => \$live,
                'separator=s'                  => \$separator,
@@ -69,6 +70,10 @@
     WARNING: ALL symlinks within the destination directory and its
     subdirectories (recursive) will be removed when using the --link option.
 
+--file filename
+
+    only rename the given file instead of the entire directory
+
 --live
 
     Include live tv recordings, affects both linking and renaming.
@@ -253,11 +258,13 @@
         }
     # Bad path
         die "$dest is not a directory.\n" unless (-d $dest);
-    # Delete any old links
-        find sub { if (-l $_) {
-                       unlink $_ or die "Couldn't remove old symlink $_: $!\n";
-                   }
-                 }, $dest;
+    # Delete any old links if the --file option is not specified
+        if (!defined($filename)) {
+            find sub { if (-l $_) {
+                        unlink $_ or die "Couldn't remove old symlink $_: $!\n";
+                       }
+                     }, $dest;
+        }
     # Delete empty directories (should this be an option?)
     # Let this fail silently for non-empty directories
         finddepth sub { rmdir $_; }, $dest;
@@ -273,10 +280,15 @@
     my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete');
     foreach my $row (@{$rows{'rows'}}) {
         my $show = new MythTV::Recording(@$row);
+
     # Skip LiveTV recordings?
         next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV');
     # File doesn't exist locally
         next unless (-e $show->{'local_path'});
+    # If the --file option has been given check to see if the current file is the one we need to rename
+        if (defined($filename)) {
+		next unless (($show->{'basename'} eq $filename) or ($show->{'local_path'} eq $filename));
+	}
     # Format the name
         my $name = $show->format_name($format,$separator,$replacement,$dest,$underscores);
     # Get a shell-safe version of the filename (yes, I know it's not needed in this case, but I'm anal about such things)
@@ -289,11 +301,15 @@
         if ($dest) {
         # Check for duplicates
             if (-e "$dest/$name$suffix") {
-                $count = 2;
-                while (-e "$dest/$name.$count$suffix") {
-                    $count++;
+                if (!defined($filename)) {
+                    $count = 2;
+                    while (-e "$dest/$name.$count$suffix") {
+                        $count++;
+                    }
+                    $name .= ".$count";
+                } else {
+                    unlink "$dest/$name$suffix" or die "Couldn't remove old symlink $dest/$name$suffix: $!\n";
                 }
-                $name .= ".$count";
             }
             $name .= $suffix;
         # Create the link

