I need help with creating a new script or rather combining existing functions to do what I described in the title. Since I am fairly new to Directory Opus and the forum I don't know how to link other threads, yet. But I have been using following functions:
Changing Filename date format to yyyy-mm-dd
function lpad( val, pad ) {
if (!pad) pad='';
var rtn=val.toString();
return (rtn.length<pad.length) ? (pad+rtn).slice(-pad.length) : val;
}
function ProduceNewName(oldname, matched, day, month, year) {
var newDate = lpad(year, "0020") + "-" + lpad(month, "00") + "-" + lpad(day, "00");
DOpus.OutputString("'" + oldname +"' - '" + matched +"' - '" + newDate +"' day:'" + day +"' month:'" + month + "' year:'"+year+"'");
return oldname.replace(matched, newDate);
}
function OnGetNewName(getNewNameData)
{
var item = getNewNameData.item;
//DD-MM-YYYY D-M-YY
var reg = new RegExp('([0-1]?\\d)[-.]([0-3]?\\d)[-.]((?:19|20)?[0-9]{1,2})|((?:19|20)?[0-9]{1,2})[-.]([0-1]?\\d)[-.]([0-3]?\\d)');
var regexMatch = reg.exec(item.name);
if (regexMatch != null) {
DOpus.OutputString(item.name + " matched 1 DD-MM-YYYY or YYYY-MM-DD");
getNewNameData = ProduceNewName(item.name, regexMatch[0],
regexMatch[2] + regexMatch[6],
regexMatch[1] + regexMatch[5],
regexMatch[3] + regexMatch[4]);
return getNewNameData;
}
//YYYYMMDD
var reg = new RegExp('((?:19|20)?[0-9]{2})([0-3]?\\d)([0-3]?\\d)');
var regexMatch = reg.exec(item.name);
if (regexMatch != null) {
DOpus.OutputString(item.name + " matched 3 YYYYMMDD");
getNewNameData = ProduceNewName(item.name, regexMatch[0], regexMatch[3], regexMatch[2], regexMatch[1])
return getNewNameData;
}
//DDMMYYYY
var reg = new RegExp('([0-1]?\\d)([0-3]?\\d)((?:19|20)[0-9]{2})');
var regexMatch = reg.exec(item.name);
if (regexMatch != null) {
DOpus.OutputString(item.name + " matched 2 DDMMYYYY");
getNewNameData = ProduceNewName(item.name, regexMatch[0], regexMatch[2], regexMatch[1], regexMatch[3])
return getNewNameData;
}
//Failed, true means no change.
return true;
}
and
@nofilenamequoting
=return "Copy MOVE HERE CREATEFOLDER="+Left(Trim(file), 4)
@nofilenamequoting
=return "Copy MOVE HERE CREATEFOLDER="+Left(Trim(file), 6)
Is there a way to combine those to get the dates from the filenames of the selection, create new folders with the format YYYY-MM-DD from the filenames and move them into the folders?