Thank you Jupe and Highend for new ideas.
get('clipboarddropeffect'); looks as a better way. This is great.
Here are two scripts, in case they will be useful for someone. Works for me, thought I don't say the code is perfect:
Code: Select all
// To create timestamped copy
$affix = getkey('PostfixNum', 'General');
$affixDate = getkey('PostfixDate', 'General');
foreach($item, <get SelectedItemsNames |>,, 'e') {
// Get the digit(s) from the used affix
$cntNumAffix = regexmatches($affix, '\d+');
// How many digits do we have? (e.g. 2 in '01')
$lenNumAffix = strlen($cntNumAffix);
// Base file (everything up to but not including the first dot)
$baseFile = regexmatches(gpc($item, 'file'), '^[^.]+');
// Keep everything after the first dot
$exts = regexreplace($item, '^[^.]+\.?');
// Generate destination file name (without path!)
if ($exts != '') {
$dstFile1 = $baseFile . '.' . $exts;
$dstFile2 = $baseFile . '.' . $exts . $affixDate . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.') . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.');
} else {
$dstFile1 = $baseFile;
$dstFile2 = $baseFile . $affixDate . $affix;
}
while (true) {
// If the destination file does NOT exist
if (exists(<curpath> . '\' . $dstFile1) == False) {
if ($exts != '') {
copyas $baseFile . '.' . $exts,, $item;
} else {
copyas $baseFile,, $item;
}
break;
}
if (exists(<curpath> . '\' . $dstFile2) == False) {
if ($exts != '') {
// Check if the 'pre' version (the one before the e.g. #2 suffix) exists
$preDstFile2 = $baseFile . '.' . $exts . $affixDate . '.' . gpc($item, 'ext');
if (exists(<curpath> . '\' . $preDstFile2) == False) {
copyas $preDstFile2,, $item;
} else {
copyas $dstFile2,, $item;
}
} else {
// Check if the 'pre' version (the one before the e.g. #2 suffix) exists
$preDstFile1 = $baseFile . $affixDate;
if (exists(<curpath> . '\' . $preDstFile1) == False) {
copyas $preDstFile1,, $item;
} else {
copyas $dstFile2,, $item;
}
}
break;
}
// Destination file DOES already exist
// Increase the digits of the affix by one
$cntNumAffix++;
// Create the new, formatted affix number
$incAffix = format($cntNumAffix, strrepeat('0', $lenNumAffix));
// Replace the digits with the incremented one(s)
$affix = regexreplace($affix, '\d+', $incAffix);
// This is the new (counted up) destination file name (again, no path!)
if ($exts != '') {
$dstFile2 = $baseFile . '.' . $exts . $affixDate . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.') . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.'),, $item;
} else {
$dstFile2 = $baseFile . $affixDate . $affix,, $item;
}
}
}
Code: Select all
// To create incremented copy
$affix = getkey('PostfixNum', 'General');
foreach($item, <clp>, <crlf>, 'e') {
// Get the digit(s) from the used affix
$cntNumAffix = regexmatches($affix, '\d+');
// How many digits do we have? (e.g. 2 in '01')
$lenNumAffix = strlen($cntNumAffix);
// Base file (everything up to but not including the first dot)
$baseFile = regexmatches(gpc($item, 'file'), '^[^.]+');
// Keep everything after the first dot
$exts = regexreplace($item, '^[^.]+\.?');
// Generate destination file name (without path!)
if ($exts != '') {
$dstFile1 = $baseFile . '.' . $exts;
$dstFile2 = $baseFile . '.' . $exts . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.');
} else {
$dstFile1 = $baseFile;
$dstFile2 = $baseFile . $affix;
}
while (true) {
// If the destination file does NOT exist
if (exists(<curpath> . '\' . $dstFile1) == False) {
if ($exts != '') {
if (get('clipboarddropeffect') == 5) {
copyas $baseFile . '.' . $exts,, $item;
} elseif (get('clipboarddropeffect') == 2) {
moveas $baseFile . '.' . $exts,, $item;
}
} else {
if (get('clipboarddropeffect') == 5) {
copyas $baseFile,, $item;
} elseif (get('clipboarddropeffect') == 2) {
moveas $baseFile,, $item;
}
}
break;
}
if (exists(<curpath> . '\' . $dstFile2) == False) {
if ($exts != '') {
if (get('clipboarddropeffect') == 5) {
copyas $baseFile . '.' . $exts . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.'),, $item;
} elseif (get('clipboarddropeffect') == 2) {
moveas $baseFile . '.' . $exts . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.'),, $item;
}
} else {
if (get('clipboarddropeffect') == 5) {
copyas $baseFile . $affix,, $item;
} elseif (get('clipboarddropeffect') == 2) {
moveas $baseFile . $affix,, $item;
}
}
break;
}
// Destination file DOES already exist
// Increase the digits of the affix by one
$cntNumAffix++;
// Create the new, formatted affix number
$incAffix = format($cntNumAffix, strrepeat('0', $lenNumAffix));
// Replace the digits with the incremented one(s)
$affix = regexreplace($affix, '\d+', $incAffix);
// This is the new (counted up) destination file name (again, no path!)
if ($exts != '') {
$dstFile2 = $baseFile . '.' . $exts . $affix . '.' . regexreplace($exts, '^.+(#\d+|@[\d-]+)\.');
} else {
$dstFile2 = $baseFile . $affix;
}
}
}
Preliminary setup: Tools > Configuration > Templates > Incremental affix: #2, Date affix: @<date yyyy-mm-dd-hh-nn>
Known issue: Each file will create its own copy window.