Hi
Looking for help/guidance in Re-Ordering and adding to a filename, first a brief background we currently use Dalim Twist to sort hundreds of files a week be it PDF or Images one particular use is to ReOrder a filename using a tool called CheckIncoming this tool uses this RegEx
([A-Z]+)([0-9]+)(.*)(-|_)([0-9][0-9][0-9][0-9][0-9][0-9])(-|_)([0-9]+)(.*)
to look for files that may be named SA1213INCOMINGFILE_123456_01.eps using
#1#2#3#7_#5#8
to ReOrder the file to be SA1213INCOMINGFILE01_123456.eps for reasons i won't go into the six digits needs to be at the end of the filename in this instance.
Twist only uses a very simple RegEx hence not to pretty.
So in Switch looking at the Rename tool we used this RegEx in the Search for
(SAd{4})(.*)(_d{6})(_|-)(d{2})(.*)
and in the Replace by
$1$2$5_$3$6
thinking it may be similar to Twists CheckIncoming or the GREP find and replace in Indesign showing our inexperience, alas it didn't work.
What to do, are we on the right track or will it have to be a Replace by a script expression?
The adding to a filename would be along the same lines Search for
(SAd{4})(.*)(_d{6})(_|-)(d{2})(.*)
and Replace by
$1$2$5_SHAD_$3$6 giving us SA1213INCOMINGFILE01_SHAD_123456.eps
Thanks
Re-Ordering a filename, adding to a filename in Switch
-
- Newbie
- Posts: 16
- Joined: Tue Sep 18, 2012 5:01 pm
Re-Ordering a filename, adding to a filename in Switch
this would do the trick in a very simple script expression:
var fileName = job.getName().split("_");
var newName = fileName[0]+fileName[2]+"_SHAD_"+fileName[1];
newName;
Cheers,
Thorsten
var fileName = job.getName().split("_");
var newName = fileName[0]+fileName[2]+"_SHAD_"+fileName[1];
newName;
Cheers,
Thorsten
Re-Ordering a filename, adding to a filename in Switch
Thorsten's script expression is of course correct, short, to the point and easy to read, but it requires the presence of the Scripting Module. In case you do not have that module here is a solution that does not require a script.
In the Rename element the first action is to replace filename proper with the single-line text with variable [Job.NameProper:Before=_].
The second action is to add a suffix to the filename proper with the variable [Job.NameProper:After=_].
The third action is again to add a suffix to the filename proper with the variable [Job.NameProper:Search=(_d{6})].
Adding _SHAD_ is a matter of adding a suffix with an inline value as action 3 and making the previous action 3 into action 4.
Freddy
In the Rename element the first action is to replace filename proper with the single-line text with variable [Job.NameProper:Before=_].
The second action is to add a suffix to the filename proper with the variable [Job.NameProper:After=_].
The third action is again to add a suffix to the filename proper with the variable [Job.NameProper:Search=(_d{6})].
Adding _SHAD_ is a matter of adding a suffix with an inline value as action 3 and making the previous action 3 into action 4.
Freddy
-
- Newbie
- Posts: 16
- Joined: Tue Sep 18, 2012 5:01 pm
Re-Ordering a filename, adding to a filename in Switch
Thanks for you replies, but I eventually worked out what I needed to do with the RegEx in the Replace tool, if anybody in interested here is what you need to do.
Files named as incoming
SA1213INCOMINGFILE_012345_001.eps
BF1113NEWFILE_879034_02.eps
in the Replace tool Action 1 - Search and Replace
search for RegEx (.*)(_d{6})(_)(d{1,3})(.*)
replace RegEx 1425
Renamed files
SA1213INCOMINGFILE001_012345.eps
BF1113NEWFILE02_879034.eps
The important thing is the brackets as these capture parts of the filename and allow you to reorder so (.*) is 1 (_d{6}) is 2 and so on, you then reference the captured parts using the backslash 1 2 ect
Files named as incoming
SA1213INCOMINGFILE_012345_001.eps
BF1113NEWFILE_879034_02.eps
in the Replace tool Action 1 - Search and Replace
search for RegEx (.*)(_d{6})(_)(d{1,3})(.*)
replace RegEx 1425
Renamed files
SA1213INCOMINGFILE001_012345.eps
BF1113NEWFILE02_879034.eps
The important thing is the brackets as these capture parts of the filename and allow you to reorder so (.*) is 1 (_d{6}) is 2 and so on, you then reference the captured parts using the backslash 1 2 ect
-
- Newbie
- Posts: 1
- Joined: Thu Jul 25, 2013 3:12 pm
Re-Ordering a filename, adding to a filename in Switch
Glad this post was here. Had a bit of a pain myself adjusting our filenames through switch but your RegEx has sorted it.
Much appreciated.
Rich
Much appreciated.
Rich