A pure function to make the changes to a filename string:
fileNameChangeF = StringJoin@ Riffle[
Pick[#, StringFreeQ[#, __ ~~ "_" ~~ NumberString] & /@ #] &@#,"."] &@
StringSplit[#, "."] &
example:
filenameList = {"abc_1234.xyz_name1.pdf", "abc_1234.xyz_222.aaa_name2.pdf",
"some_name.pdf"}
fileNameChangeF/@filenameList
(* {"xyz_name1.pdf", "aaa_name2.pdf", "some_name.pdf"} *)
EDIT: what the function does step-by-step:
filenameList[[1]] (* input filename string *)
(* "abc_1234.xyz_name1.pdf" *)
StringSplit[#, "."] &[%] (* split at "."s *)
(* {"abc_1234","xyz_name1","pdf"} *)
StringFreeQ[#, __ ~~ "_" ~~ NumberString] & /@ %
(* find the parts free of the pattern *)
(*{False,True,True} *)
Pick[%%, %] (* pick those parts *)
(* {"xyz_name1","pdf"}*)
Riffle[%, "."] (* insert "."s back in *)
(* {"xyz_name1",".","pdf"} *)
StringJoin[%] (* ... and join *)
(* "xyz_name1.pdf" *)
Mapped to a list of filenames fileNameChangeF/@filenameList
, it does the same operations on each filename.
?Rename*
;?StringR*
and give it a shot. Its not a very difficult problem really. $\endgroup$?Regular*
$\endgroup$