Rename by substring

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

Rename by substring

Post by highend » 25 Oct 2019 22:15

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 160 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 259 times
The result would look like this:
result.png
result.png (12.52 KiB) Viewed 160 times
Current version:
Rename by substring_v0.3.xys
(6.27 KiB) Downloaded 36 times
Old version(s):
Rename by substring_v0.2.xys
(5.57 KiB) Downloaded 26 times
Rename by substring_v0.1.xys
(3.66 KiB) Downloaded 22 times
Version history:
/*
@Changelog:
+++ major new feature
+ new feature
* changed feature
- removed feature
% improved performance
! fixed minor bug
!!! fixed major bug

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 or highend (at) web (dot) de

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

Re: Rename by substring

Post by highend » 27 Oct 2019 09:01

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 or highend (at) web (dot) de

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

Re: Rename by substring

Post by highend » 08 Nov 2019 17:54

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 or highend (at) web (dot) de

Post Reply