by Luuk » Sun Aug 03, 2025 2:58 am
Its unfortunate but I wasnt able to answer, ever since the forums started requiring the javascript.
So Im just using someone else's browser, that does always conduct the javascript for any web-pages.
At first, when it was only 2-SubfolderNames, Im just using 2 if-statements, trying to make everything look easier.
But now with 5, its probably better to make 1-regex for all-5, then store parts of the matched-path into variables.
This way, if you get more subfolders in the future, the below format should be a little easier to modify...
// Create 1-regex to match certain folderpath-formats like below, so that all subfiles below there, should be targeted for renaming...
// Folder1 starts like "#### - ", then 1-allowed recursion-folder starting like "20## ", then any of your allowed SubfolderNames.
// If your recursion-folders dont always start with '20## ', just remove '20\d\d ' to allow 1-possible recursion-folder of any name.
// If needing more recursion to find your allowed SubfolderNames, can edit the "1" in {0,1} to set their maximum-depth below Folder1.
// Remember, its still only matching your folderpath-formats, all subfiles below allowed SubfolderNames still get targeted for renaming.
// To limit file-recursion below allowed SubFolderNames, can insert ($|([^\\]+\\){0,2}$) just before /i, editing 2 for your max file-recursion).
myFormats = new RegExp(/\\(\d{4}) - [^\\]+\\(?:20\d\d [^\\]+\\){0,1}(employment eligibility|personnel file|i-9s|investigations|medical records)\\/i)
// if (folderpath matches "\(4-digits) - Name\(?:AllowedRecursion)(Allowed SubFolderNames)\" case-insensitive AND is not a folder)...
if (object('folder').match(myFormats) && object('isdir') == false) {
// If found, store both matched-parts of folderpath (lower-cased) into path, remembering that .match() stores them as an [array]!
// This is why we used (grouping) inside of myFormats, so that with an array, path[1]=id# and path[2]=SubFolderName.
path = object('folder').toLowerCase().match(myFormats)
// Depending on the 5-SubfolderNames matched by path[2], create insert to store some insertion-text
if (path[2].startsWith('e')) insert = 'EMPLOYMENT_AGREEMENT'
if (path[2].startsWith('p')) insert = 'PAYROLL_AND_BENEFITS'
if (path[2].startsWith('m')) insert = 'MEDICAL'
if (path[2].startsWith('i-')) insert = 'TAX_FORM'
if (path[2].startsWith('in')) insert = 'INVESTIGATIONS'
// But what if the filename has already been inserted, and should not be renamed again with this insertion-text?
// We lowercase both now-name and insert for case-insensitive comparison, then only rename if insertion-text is missing...
// If now-name is not matched by insertion-text, then create the new-name like...
if (!name.toLowerCase().match(insert.toLowerCase())) newName = path[1] + '-' + insert + '-' + name}
It looks like your last-post decided the insertion-text might need to change, so this format should be easier to modify.