I've come across a number of sites that now include #hashtag text in the filenames. I don't want those, as they tend to make the pathname excessively long.
I raised the question on
this thread.
I wrote this script to strip them out. It's called via Event Scripter using a Packagizer Hook:
Code:
if (linkcheckDone) {
var myPackagizerLink = link;
var fileName = myPackagizerLink.getName();
var re, ext, newName;
if (fileName !== null && fileName.includes("#")) {
ext = fileName.slice((fileName.lastIndexOf(".") - 1 >>> 0) + 2);
if (ext !== "") {
ext = "." + ext.toLowerCase();
}
fileName = fileName.substr(0, (fileName.length - ext.length));
rgx = new RegExp("#[a-zA-Z0-9_]+", "gi");
newName = fileName.replace(rgx, "");
rgx = new RegExp("\\s\\s+", "gi");
newName = newName.replace(rgx, " ");
newName = newName.trim();
myPackagizerLink.setName(newName + ext);
}
}
I'd welcome suggestions on improving it, or accomplishing the goal in another manner.