Move all to parent & delete - my most-used script
Posted: 22 Aug 2020 06:49
I have many very useful scripts but this has probably been used 10x any other, so worth sharing.
All it does is move everything from the current List folder to the parent of that folder, then delete the now-empty current folder. Yes that's simple and I know it can be better programmed, but this has proven to be bulletproof in countless moves.
I have this script assigned to a custom toolbar button, with a big red 'M' icon. If I hold 'shift' while clicking on the button, the operation proceeds with no prompt. That's what I always do - except when I click it in error, without shift pressed. Then I'm glad to have the prompt.
All it does is move everything from the current List folder to the parent of that folder, then delete the now-empty current folder. Yes that's simple and I know it can be better programmed, but this has proven to be bulletproof in countless moves.
I have this script assigned to a custom toolbar button, with a big red 'M' icon. If I hold 'shift' while clicking on the button, the operation proceeds with no prompt. That's what I always do - except when I click it in error, without shift pressed. Then I'm glad to have the prompt.
Code: Select all
// Move all to parent and delete folder
setting "BackgroundFileOps", 0;
focus "L";
$addbar = tab("get", "term");
end (strpos($addbar, "/:flat")!=-1), "Not usable in branch view!";
if (<get shift>==0) {msg "Move all to parent & del folder?", 1;}
//Need Shift released else Goto makes new tab; delay else loop too tight
while (<get "shift">!=0) {Status "RELEASE SHIFT!", "FF0000"; wait 50;}
$orig = <curpath>;
$parent = gpc(<curpath>, "path");
$filoc = gettoken($orig, -1, "\");
$ctmark = strpos($filoc, ".");
if ($ctmark!=-1) {
$newnam = replace($filoc, ".", "_");
renameitem($newnam, $orig, 4);
$filoc = $newnam;
}
goto $parent.'\'.$filoc;
selfilter "*";
moveto $parent;
focus "T"; //Ensure folder empty before deleting it
$fsizes = foldersize(, "<d>|<f>|<r>", 1);
$focount = gettoken($fsizes,1,"|");
$ficount = gettoken($fsizes,2,"|");
$bycount = gettoken($fsizes,3,"|");
$totcount = $focount + $ficount + $bycount;
end $totcount!=0, "Delete stopped - folder not empty!!";
delete 1, 0, ":tree";
goto $parent;
focus "L";