Page 1 of 1

Modify selected file names

Posted: 07 Jan 2012 21:27
by southwick
I am new to XYplorer and this forum so please answer in newby talk! I have many filename similar to nikita.s02e11.HDTV.XviD-ASAP.[VTV].avi
and would like thrm to be renamed to: Nikita S02E11.avi

I have looked into regular expressions but I'm sorry too admit that that subject is over my head. Any help would be greatly appreciated.

Re: Modify selected file names

Posted: 07 Jan 2012 21:45
by j_c_hallgren
Hi and welcome to the XY forums!

Just wanting to make sure of your "problem definition":
1) all involved files have 5 name segments (and thus 4 '.') before the extension, right?
2) you want to uppercase the 2nd segment in all cases?
3) and you want the first char of 1st segment also uppercased?

Re: Modify selected file names

Posted: 07 Jan 2012 22:06
by southwick
Super fast reply, thanks. Yes to all three of your questions. Looking forward to your decription of how to acomplish this!!!

Re: Modify selected file names

Posted: 07 Jan 2012 22:14
by j_c_hallgren
southwick wrote:Super fast reply, thanks. Yes to all three of your questions. Looking forward to your decription of how to acomplish this!!!
Unfortunately, while I'm often quick at replies, I'm not that great at regex's either :oops: but what I wanted to do was just make 100% sure of issue as we've had new users say "i want to do x, y and z" but then they start adding all kinds of exceptions (like 'a, b and c") and new rules such that it makes coding a solution almost impossible...

However, we have a GREAT set of regular users here so I'm sure you'll hear from one of them within a few hours at most with a solution.

Rename using parts only and change case too

Posted: 07 Jan 2012 22:33
by Stefan
Hi and welcome. Thanks jc

RegEx: i am not sure if we can use \u \L syntax with XYplorer regex engine. Anyway...

So instead we can use an little script to do such things (if you use the pro version?) like this one;

Code: Select all

    $ITEM = "<curname>";
  //$ITEM = "nikita.s02e11.HDTV.XviD-ASAP.[VTV].avi"; 
  //       Nikita S02E11.avi
   
   //strpos(haystack, needle, [start], [matchcase])
   $DotPos1 = strpos($ITEM, "."); 
   //substr(string, [start], [length])
   $Part1 = substr($ITEM, , $DotPos1);
   $Part1 = recase($Part1, "sentence"); 
    
   //strpos(haystack, needle, [start], [matchcase])
   $DotPos2 = strpos($ITEM, ".", $DotPos1); 
   //substr(string, [start], [length])
   $Part2 = substr($ITEM, $DotPos1 +1, $DotPos2);
   $Part2 = recase($Part2, "upper");
   
   $DotLast = strpos($ITEM, ".", -1);
   $Ext = substr($ITEM, $DotLast);
   
   msg $Part1 $Part2$Ext;
  // renameitem($Part1 $Part2$Ext, $ITEM);
Whit this script we can split the file name into parts and also change the case at easy.
For how to use such an script see my footer or read the help.
If the msgbox shows the right modifications we can enable the real renaming. Even we can loop through all (selected) files.


.

Re: Modify selected file names

Posted: 07 Jan 2012 22:48
by highend
This was my solution (although I'm a bit late):

Code: Select all

$SelectedItems = get("SelectedItemsPathNames", "|");
	
	foreach($Item, "$SelectedItems", "|") {
		$FindBS = strpos($Item, "\", -1);
		$DstPath = substr($Item, 0, $FindBS);
		$FindExt = strpos($Item, ".", -1);
		$Ext = substr($Item, $FindExt +1, );
		$Filename = substr($Item, $FindBS +1, ($FindExt - $FindBS -1));

		$First = recase(gettoken($Filename, 1, "."), t);
		$Second = recase(gettoken($Filename, 2, "."), u);

		rename b, "$First $Second.$Ext /e", p, "$Item";
	}
Tested it with some of your filenames and it's working fine so far.

You just have to select all files that you want to be renamed and execute this script afterwards.

Re: Modify selected file names

Posted: 08 Jan 2012 00:14
by Marco
My 0.02$...

The first idea that comes to my mind is that you've a folder with files named nikita.s02e##.HDTV.XviD-ASAP.[VTV].avi , where ## stands for a two-digit number.
Easiest thing to do is select all the episodes of the season, then press Shift+F2. In the rename box that will appear write Nikita S02E<#01>, then press Enter. You should accomplish what you want (at least, experience tells me so ;) ).

Re: Modify selected file names

Posted: 08 Jan 2012 01:31
by southwick
Thank you all!! I will try to learn from each code(?) that you so kindly submitted.

Re: Modify selected file names

Posted: 08 Jan 2012 10:49
by PeterH
I'd change Stefans last 2 lines to:

Code: Select all

   msg "$ITEM<crlf>$Part1 $Part2$Ext";
  // renameitem("$Part1 $Part2$Ext", "$ITEM");
(Especially the quotes around "$Part1 $Part2$Ext" - the rest is cosmetic...)

And I must say: I like highends "gettoken"s - very direct!

Re: Modify selected file names

Posted: 16 May 2012 01:13
by mithrin
I'm not sure if it would help but if someone could use it as a base-line and modify it. It's was post
http://www.xyplorer.com/xyfc/viewtopic. ... +Extension+ Regular Expression Renaming Suite

The secret I took from this was (\.[^\.]*) this obtains the extension regardless of how many dot's that are in the name. I've been experimenting for the same reason to modify TV file names that I download, so I can rename them automatically.

Image

Re: Modify selected file names

Posted: 16 May 2012 10:21
by highend
The question is, if your regex would be faster than our two lines

Code: Select all

      $FindExt = strpos($Item, ".", -1);
      $Ext = substr($Item, $FindExt +1, );
And the next question is, does that matter when you're about to rename a single / a handful of files...

:D