Rename File or Folder if the name contains certain text
Posted: 20 Mar 2015 17:51
Can someone help me with a script that if a selected filename or folder name contains "- Copy" at the end, then have "- Copy" changed to today's current date "- (yyyy-mm-dd)". On the flip side, if it does not contain "- Copy" then just append "- (yyyy-mm-dd)" to the end of the filename/folder name (of course, before the extension if it is a file).
I found the code below here in the forum and it is very close to something that I would like. I tried plugging in the stuff that I am trying to do, but I am not having any luck.
Thank you for any help that you can provide.
I found the code below here in the forum and it is very close to something that I would like. I tried plugging in the stuff that I am trying to do, but I am not having any luck.
Thank you for any help that you can provide.
Code: Select all
foreach($item, "<get SelectedItemsPathNames |>") {
if (exists($item) == 2) { $baseName = getpathcomponent($item, "file"); $ext = ""; } // Folder
else { $baseName = getpathcomponent($item, "base"); $ext = "." . getpathcomponent($item, "ext"); } // File
if (regexmatches($baseName, "-SAVE$") != "") { // Contains "-SAVE"
$newName = regexreplace($baseName, "-SAVE$");
copyitem $item, "<curpath>\" . $newName . $ext;
} else { // Does not contain "-SAVE"
renameitem($baseName . "-SAVE" . $ext, $item);
}
}