Is there a way using Rename Special to truncate the first or last X characters of the base of a file name(s)?
Failing that is there an alternative method within XY?
Rename Special to truncate
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: Rename Special to truncate
aurumdigitus wrote:Is there a way using Rename Special
to truncate the first or last X characters of the base of a file name(s)?
Failing that is there an alternative method within XY?
Rename Special > RegEx Rename
to truncate the first X characters of the base of a file name
use
.{amount}(.+) > $1
like e.g.
.{6}(.+) > $1
Explanation:
. >>> match any sign
{amount} >>> match that amount of the last regex (the dot here)
(.+) >>> match one-or-more of any sign and group this for an backreference use with $1
-- -- --
Rename Special > RegEx Rename
to truncate the last X characters of the base of a file name looks a bit more tricky
use
(.+).{amount}\.(.+) > $1.$2
like e.g.
(.+).{3}\.(.+) > $1.$2
Explanation:
(.+).{3} >>> like above, match one-or-more of any sign, followed by n amount of any sign
\. >>> till an real dot, followed by
(.+) >>> the extension
Here we have two backreferencing groups to use in the replacement as $1 dot $2
BTW, such back references are also useful to swap name part.
HTH in some way ?
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Rename Special to truncate
Stefan - thanks for the very cogent explanation! Was hoping to avoid RegEx which is why Rename Special was first but if that is what it takes so be it.
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Rename Special to truncate
Stefan - Just entered by hand you RegEx syntax into my XY notebook. By hand because as an erstwhile pedagogue know that serves to help cement the knowledge into the cerebral cortex. (Forgive the alteration.
)
BTW - the new Rename Special|Edit Item Names (in Beta version) is very utilitarian if the file list is short but in this case was too laborious hence the recourse to RegEx.
BTW - the new Rename Special|Edit Item Names (in Beta version) is very utilitarian if the file list is short but in this case was too laborious hence the recourse to RegEx.
XYplorer Beta Club