Page 1 of 1
Script to batch truncate filenames
Posted: 13 Apr 2009 04:44
by thompsonao
Hello - I apologize if this is elementary - I'm new to scripting - but does anyone have a script for truncating file names (in batch) to a certain length? For example:
npr_100550000__kip_ipx_1940137902_1234755987.mp3
to:
npr_100550000.mp3
(13 characters)
Many thanks,
Al
Re: Script to batch truncate filenames
Posted: 13 Apr 2009 12:36
by serendipity
Hi and Welcome to XYplorer,
You can do it easily with
regexp rename script posted previously by TheQwerty. If that doesnt work for you, then try the below script:
Code: Select all
//Truncate script
global $g_truncate;
input $g_truncate, remove characters after?, 13;
$selected = getinfo ("SelectedItemsPathNames", "|");
replace $selected, $selected, <curpath>\, ;
filter $selected;
sel 1;
sub "_eval";
"_eval"
$count = getinfo("CountSelected");
$eval = $count ==1 ? "_start" : "_end";
sub $eval;
"_start"
global $g_truncate;
substr $new, <curbase>, ,$g_truncate ;
rename b, $new;
sel +1;
sub "_eval"
"_end"
filter;
status "Done!";
Re: Script to batch truncate filenames
Posted: 19 Apr 2009 22:39
by thompsonao
Worked great - many thanks!
-AOT