Page 1 of 1

Possible to show size when deleteing

Posted: 28 Mar 2015 08:54
by fogg
Hello,
I want to know total size of files when deleting something. Is it possible? I think XYplorer is able to do this, but I didn't find any option. :(

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 09:06
by admin
Edit | Select | Selection Stats?

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 09:27
by bdeshi
Try this. You'll get a confirmation before the actual delete confirmation. Safety belt.

Code: Select all

 $focus = get('FocusedControl');
 $items = ($focus == 'T') ? <curpath> : ( ($focus == 'L') ? get('SelectedItemsPathNames', '|') : '' ) ;
 end ($items == '');
 unset $focus;
 $grandsize = 0; $size = 0;
 foreach ($item, $items, '|'){
  $size      = (exists($item) != 1) ? foldersize($item, '<r>', 1) : filesize($item) ;
  $grandsize = $grandsize + $size;
 }
 $grandsize = formatbytes($grandsize, 'FLEX');
 $ques      = "You're about to delete $grandsize in total.<crlf 2>Continue?";
 if (confirm($ques,,,4/**btns:Yes/No*/) == 1){ #169 ;/*File > Delete*/ }
This will display total size of all selected files and folders before deleting, so sometimes the calculation might take sometime. (Although in my short tests the performance was surprisingly fast! :shock: )

Now You know there are different shortcuts for different types of deletions? (delete skip locked, delete without recycling,...) Well, how about making this behave like another extra mode? Just assign it a shortcut with delete button! Here's how.
  • Open Main Menu > User > Manage commands
  • pick the "Run script" category.
  • Click New > add new command (or just press INSERT key) .
  • Enter "Delete (show total size)" in the "Caption" box. Or enter whatever you want to call it.
  • Press the EDIT button beside "Script" box. In the opened textbox, paste the whole script above. (make sure the spaces are there before each line)
  • "OK" out out of there.
  • Now set up a hotkey with "Assign keyboard shortcut" button. Press that button, then press DELETE key to jump to free shortcuts with DELETE.
    I suggest you also check "On keyup"
Alright! Now you can do DELETE: regular delete prompt, SHIFT+DELETE: delete (no recycling), CTRL+DELETE: Delete (skip locked items), CTRL+SHIFT+DELETE: delete (no recycling, skip locked), and [CTRL+] SHIFT+ALT+DELETE: delete (show total size) !

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 09:28
by fogg
admin wrote:Edit | Select | Selection Stats?
Thanks, but That is not quick, I need to use that menu, then again do delete.

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 10:36
by admin

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 13:22
by fogg
:appl: :appl: :appl: :appl: Thank you very much SammaySarkar! This is exactly what I needed!
I use the Ctrl+Del for this script because I don't use Delete (Skip Locked) #171
But can it delete with only one confirmation?

Again Many thanks,
Phil

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 13:29
by bdeshi
My pleasure. :)
fogg wrote:But can it delete with only one confirmation?
Sure. Replace the very last line,

Code: Select all

 if (confirm($ques,,,4/**btns:Yes/No*/) == 1){ #169 ;/*File > Delete*/ }
with this:

Code: Select all

 if (confirm($ques,,,4/**btns:Yes/No*/) == 1){ delete 1, 0, $items; }
Again make sure there's (at least) one space at the beginning of the line.

This will delete selected items to recycle bin. Replace the 1 after "delete" to 0 to delete permanently; I don't suggest that though.

Re: Possible to show size when deleteing

Posted: 28 Mar 2015 13:36
by fogg
It's perfect now! :appl: :appl: Wioderful!

Re: Possible to show size when deleteing

Posted: 04 Apr 2015 20:10
by fogg
Hello again.
I have a problem. nothing happens When I press control + delete to open this script. Next time, it opens a message box saying

Code: Select all

a user-defiend command (#1403) is not allowed to call itself
:?: :?: :?:

Re: Possible to show size when deleteing

Posted: 04 Apr 2015 20:12
by fogg
more: also short time later opens a script error box as

Code: Select all

Access is denied

Re: Possible to show size when deleteing

Posted: 05 Apr 2015 10:23
by bdeshi
fogg wrote:Hello again.
I have a problem. nothing happens When I press control + delete to open this script. Next time, it opens a message box saying

Code: Select all

a user-defined command (#1403) is not allowed to call itself
:?: :?: :?:
This is because you'd selected a really huge folder and XY needed some time to calculate the total size. But you called the script again meanwhile, without letting the previous instance finish it's calculation.
So if this happens again, remember that the script hasn't died fighting an error but just needs more time.
Also remember, to stop calculation at any time, press ESC (twice). :wink:
fogg wrote:more: also short time later opens a script error box as

Code: Select all

Access is denied
You selected something that XY cannot delete. Say maybe a hard disk Drive root, C:\, D:\ ... ? (that's where I got the same result) Y'know, In this case even for usual deletion XY displays an alert, which is not much less alarming than an scripting error. :x

Hmm, the script better not calculate at all when drives are selected, but another solution is: just don't trigger it on whole drives! :kidding:

Re: Possible to show size when deleteing

Posted: 05 Apr 2015 10:51
by PeterH
@Sammay: show per Status cmd that script is working, and then when it's finished?
(Use Color to clearly show progress state.)

This at least gives some hint to the user.

Re: Possible to show size when deleteing

Posted: 05 Apr 2015 16:13
by bdeshi
I tried it, but since size of each selected folder/file is calculated in a single statement, status update will still seem to freeze/stutter if that folder happens to be large.

Anyways, here's that script with periodic updates:

Code: Select all

 $focus = get('FocusedControl');
 $items = ($focus == 'T') ? <curpath> : ( ($focus == 'L') ? get('SelectedItemsPathNames', '|') : '' ) ;
 end ($items == '');
 unset $focus;
 $grandsize = 0; $size = 0;
 foreach ($item, $items, '|'){
  $size      = (exists($item) != 1) ? foldersize($item, '<r>', 1) : filesize($item) ;
  $grandsize = $grandsize + $size;
  status "calculated size: " . $grandsize ,, 'progress';
 }
 $grandsize = formatbytes($grandsize, 'FLEX');
 $ques      = "You're about to delete $grandsize in total.<crlf 2>Continue?";
 if (confirm($ques,,,4/*btns:Yes/No*/) == 1){ #169 ;/*File > Delete*/ }

Re: Possible to show size when deleteing

Posted: 08 Apr 2015 03:40
by eil
SammaySarkar, can you please modify script with extra safety to check if Delete is happening on non-hard drives and taking it to user's notice?
like having a variable with list of hard-drive letters user has, and if any is present in pathes, add extra line to that Question-dialog, stating that "Delete on < G > drive, will be permanent!"

Re: Possible to show size when deleteing

Posted: 10 Apr 2015 18:14
by eil
modified script myself, maybe someone will find it useful too(just use your hard-drive letters). i'd only wish i could "use bbcode" to mark some words with bold or underline.. :cry:
now shows size, number of items, drive letter and additional warning if it's not stated drives.

Code: Select all

 $focus = get('FocusedControl');
 $items = ($focus == 'T') ? <curpath> : ( ($focus == 'L') ? get('SelectedItemsPathNames', '|') : '' ) ;
 end ($items == '');
 $drive = substr("<curpath>", , 1); //check for letter
 if ($drive == "C" || $drive == "D" || $drive == "E" || $drive == "F") {$warning = ''} else {$warning = "This will be PERMANENT!<crlf>"};
 unset $focus;
 $grandsize = 0; $size = 0; $num = 0;
 foreach ($item, $items, '|'){
  $size      = (exists($item) != 1) ? foldersize($item, '<r>', 1) : filesize($item) ;
  $grandsize = $grandsize + $size;
  $num++;
  status "calculated size: " . $grandsize ,, 'progress'; }
 $grandsize = formatbytes($grandsize, 'FLEX');
 $ques = "You're about to delete $num items <crlf>$grandsize from = $drive:\ <crlf 2>$warning  Continue?";
 if ($warning != '') {beep 2000, 50; beep 2000, 50;};
 if (confirm($ques,,,4/**btns:Yes/No*/) == 1){ delete 1, 0, $items; } //to Recycle