Modify selected file names

Discuss and share scripts and script files...
Post Reply
southwick
Posts: 3
Joined: 07 Jan 2012 21:14

Modify selected file names

Post 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.

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Modify selected file names

Post 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?
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

southwick
Posts: 3
Joined: 07 Jan 2012 21:14

Re: Modify selected file names

Post by southwick »

Super fast reply, thanks. Yes to all three of your questions. Looking forward to your decription of how to acomplish this!!!

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Modify selected file names

Post 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.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Rename using parts only and change case too

Post 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.


.

highend
Posts: 14639
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Modify selected file names

Post 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.
One of my scripts helped you out? Please donate via Paypal

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Modify selected file names

Post 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 ;) ).
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

southwick
Posts: 3
Joined: 07 Jan 2012 21:14

Re: Modify selected file names

Post by southwick »

Thank you all!! I will try to learn from each code(?) that you so kindly submitted.

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Modify selected file names

Post 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!

mithrin
Posts: 15
Joined: 15 Jan 2012 01:56

Re: Modify selected file names

Post 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

highend
Posts: 14639
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Modify selected file names

Post 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
One of my scripts helped you out? Please donate via Paypal

Post Reply