Here's a test script:
Code: Select all
// Test Script - takes a file like "the before.txt" and *should* rename it to "The After - the before.txt"
foreach($token, <get selecteditemspathnames |>)
{
// Copy filename to variables.
set $work_name, <curname>;
// Set variable to store orig filename.
set $work_origname, <curname>;
regexreplace $work_name, $work_name, "before", "after";
regexreplace $work_name, $work_name, "\.txt", "";
// Workaround to change case for the title to Title Case.
rename re, "^.*>>$work_name";
#126;
set $work_name, <curname>;
// Final file rename - re-attach original name.
rename re, "^.*>>$work_name - $work_origname";
}
This script takes a file like "the before.txt" and *should* rename it to "The After - the before.txt"
Now, here's what's going on. If I run this on a single file, it works exactly as it should. But if I run it on more than one file, let's say "the before 1.txt" and "the before 2.txt", I get a whole string of errors that it can't rename one of the files because it would collide with an existing file.
It's acting like it's working on the second file before it's finished processing the first, which would - of course - cause problems.
Can someone tell me if I'm making a mistake, or if the foreach function is buggy?
XYplorer Beta Club