Special type of renaming

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
vsub
Posts: 69
Joined: 23 Nov 2010 19:07

Special type of renaming

Post by vsub »

I was always wondering since xyp have tons of features...is it possible to delete part of multiple files(for example the first 5 letters/digits)names

For example if I have files named
01 - Name 01
02 - Name 02
03 - Name 03
is there is some way to delete only the first 5 letters/digits and to leave the names like this
Name 01
Name 02
Name 03
Also the same thing but to delete the last for example 3 letters/digits regardless of how long the name of each file is...only the delete the last 3 letters/digits of the file name

Maybe it's not possible with any program but I just wanted to ask(I have other more complicated ways to do it)

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

Re: Special type of renaming

Post by highend »

Sure. Right click them an select Rename Special - Regex Rename.

E.g.:
"^[0-9]+\s+-\s+ > " (without quotation marks and don't forget the space after the greater than sign)

Does the following:

1.) Start from the beginning of a line
2.) Look for any numer between 0 and 9 and repeat as long as needed
3.) Select one or more spaces
4.) Select the "-" sign
5.) Select one or more spaces

-> Replace the selected stuff with nothing

As an alternative, write a script, that let's you choose between several regexes that you need quite often

Begin with:

Code: Select all

$Formats = "<regex1>|<regex2>|...";
$RegEx = inputselect("Select your destination format", "$RegEx", "|", 4);
and then use a foreach() loop with regexreplace() in it and put in on a button.

One click, one selection, done.
One of my scripts helped you out? Please donate via Paypal

vsub
Posts: 69
Joined: 23 Nov 2010 19:07

Re: Special type of renaming

Post by vsub »

Ok lets see if I understand it correctly

^ means start looking at the beginning of the file name

[0-9] placed at the beginning means look for digits between 0-9(no matter how many they are one after another but if there is a letter between them,that file name will be ignored...this just looks for digits that are one after another and are at the beginning of the file name)

+ mean and also look for

\s means space

The - is just the - in the file name

And after > is with what to replace all of the funded parts of the file name

Now how about deleting x number of characters of the end of the file name
Name 01 to become Name is I want to delete the last 3 characters/digits

Creating scripts is little complicated for me :p

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

Re: Special type of renaming

Post by highend »

but if there is a letter between them,that file name will be ignored...this just looks for digits that are one after another and are at the beginning of the file name)
Correct.
+ mean and also look for
No, it means at least one time OR multiple times in a row
And after > is with what to replace all of the funded parts of the file name
+

"Deleting things^^" isn't the right thing for regexes. It all depends on what you have and what PATTERNS are to replaced.

If you always want to delete a FIXED number of characters (no matter what they are and you don't know if they follow a common pattern) you have to use a different solution (because as far as I'm aware of, the regex support of XYplorer misses {} brackets).

Stefan wrote something a while ago. It iterates through the whole string, counting at which position separators are occuring and is able to cut parts of the string because of this.

Isn't too hard too adapt to your problem but first:

Be sure, how your files can look like (namewise) and reply back if it's enough to always remove x number of characters (either at the beginning or at the end of a line).
One of my scripts helped you out? Please donate via Paypal

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

Re: Special type of renaming

Post by Stefan »

Here is an simple RegEx

(.{3})(.+)(.{3})(\..{3}) > $1$2$3$4

Explanation:
(..) will be used to store that what is matched by the regex into an group.
They are counted from left to right and can be accessed by $1, $2,...


An dot . will match any sign (digit, char, sign, punctuation)
{3} will match 3 times the expression right left before, here three time the dot.


.+ will match any sign due the dot, and one-or-more of this due the '+'


\. will escape the meaning of the dot and match an dot literary.
So (\..{3}) will match an dot followed by three signs, > the extension (if three signs, and not e.g. "HTML")


SO (.{3})(.+)(.{3})(\..{3})
will match three signs | one-or-more of any signs | three signs again | followed by the extension




" > " is the XYplorer RegEx-Rename-Find/Replace-Delimiter


$1$2$3$4 will replace with the content of all four groups , so nothing is renamed here.

But you can use this for your case:

FROM:
12345678.txt
TO:
45678.txt
USE:
(.{3})(.+)(.{3})(\..{3}) > $2$3$4

Meaning: just replace the groups you really need.


FROM:
12345678.txt
TO:
12345.txt
USE:
(.{3})(.+)(.{3})(\..{3}) > $1$2$4



May the Preview with you!


.

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: Special type of renaming

Post by aimy »

Is there a list of all possible Regex & explanation included in the XYplorer documentation?

Thank you.

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

Re: Special type of renaming

Post by Stefan »

aimy wrote:Is there a list of all possible Regex & explanation included in the XYplorer documentation?

Thank you.
No, but browse to google and type regex and press enter.
You will find f.ex.
http://en.wikipedia.org/wiki/Regular_expression
http://www.regular-expressions.info/

Post Reply