Rename by substring

Discuss and share scripts and script files...
Post Reply
highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Rename by substring

Post by highend »

Imagine you have files (or folders) like this:
FIRSTNAME.LASTNAME.119399697_INPROGRESS_DHM PICKLIST.REPORT20191024_100516.txt
FIRSTNAME.LASTNAME.119399698_INPROGRESS_DHM PICKLIST.REPORT20191024_100517.jpg
FIRSTNAME.LASTNAME.119399699_INPROGRESS_DHM PICKLIST.REPORT20191024_100518.mkv
and you want to rename them by removing all parts apart from FIRSTNAME, LASTNAME and
the ascending number before the extension. Additionally we want to replace all used
separators (dots, underscores) with a single one, e.g. a hyphen.

The resulting names should be:
FIRSTNAME-LASTNAME-100516.txt
FIRSTNAME-LASTNAME-100517.jpg
FIRSTNAME-LASTNAME-100518.mkv
This would require a regex rename in XY...

To make things a bit easier I wrote this little script. It is a "define the parts to keep" from a file/
folder name. It throws away all other parts. File extensions are retained. It's nothing more
than a little regexp pattern / remove part generator...

It requires a two step process. In the first one you need to enter the separator(s) that are used to
chop the names into parts. These separators are remembered between each call of the script.
The script assumes that all selected files / folders are named using the same pattern (= have
the same separators and the same number of parts. File extensions don't count as a part).

You can define a single separator to use in the final output if you add a trailing "|" to the input,
followed by the separator you need.
E.g. for the above we would use .,_|-...
separators.png
separators.png (4.09 KiB) Viewed 3105 times
In the second step you're entering the numbers of the blocks you want to keep, separated
by commas. E.g. for the above example we would need to use: 1,2,7...
keep.png
keep.png (3.14 KiB) Viewed 3204 times
v0.4 supports a delete block(s) syntax, e.g.: -2,-4...

A mix of both syntaxes is not allowed!

The result would look like this:
result.png
result.png (12.52 KiB) Viewed 3105 times
Current version:
Rename by substring_v0.4.xys
(7.92 KiB) Downloaded 96 times
Old version(s):
Rename by substring_v0.3.xys
(6.27 KiB) Downloaded 213 times
Rename by substring_v0.2.xys
(5.57 KiB) Downloaded 163 times
Rename by substring_v0.1.xys
(3.66 KiB) Downloaded 170 times
Version history:
/*
@Changelog:
+++ major new feature
+ new feature
* changed feature
- removed feature
% improved performance
! fixed minor bug
!!! fixed major bug

v0.4
+ Support for a delete part(s) syntax. Prefix ALL numbers with a "-".
E.g.: -2,-4
A mixed syntax (keep AND delete) is NOT allowed.

v0.3
+ Support for replacing all separators with a single one. E.g. you could
replace all hyphens and underscores with a dot, etc.

v0.2
+ Support for multiple separators. Enter them with either a comma or a
semicolon between them! E.g.: to use a dot, a hyphen and an underscore,
enter:
a.) .,-,_
or
b.) .;-;_
The order of the entered separators does NOT matter!

v0.1
• Initial release
*/
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Rename by substring

Post by highend »

v0.2 uploaded

Multiple separators are now supported (otherwise you wouldn't be able to do the renaming for more complex files)...
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Rename by substring

Post by highend »

v0.3 uploaded

Now you can define a separator for the final output that is used to replace all other ones.
E.g. If the input files use a dot and an underscore you could create an output that only
uses a hyphen instead...
One of my scripts helped you out? Please donate via Paypal

yuyu
Posts: 114
Joined: 19 Jun 2018 12:40

Re: Rename by substring

Post by yuyu »

Very helpful, thank you.
Sometimes "define the parts to delete" feature could be useful too. Is it possible to add?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Rename by substring

Post by highend »

Try v0.4
One of my scripts helped you out? Please donate via Paypal

yuyu
Posts: 114
Joined: 19 Jun 2018 12:40

Re: Rename by substring

Post by yuyu »

highend wrote: 23 Jan 2022 11:26Try v0.4
Great! Tried it and haven't noticed any errors yet. Thank you.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Rename by substring

Post by highend »

Ok, added v0.4 to the first post
One of my scripts helped you out? Please donate via Paypal

Post Reply