Script for deleting all files except by selected file type

Discuss and share scripts and script files...
Post Reply
zridling
Posts: 140
Joined: 29 Jul 2006 06:12
Location: Chicago, US
Contact:

Script for deleting all files except by selected file type

Post by zridling »

Using the UDC (User-Defined Commands), I've created a simple script from commands and assigned an keyboard shortcut (ALT+6 in my case):
________________________________________________
#254;#252;#169;#642
(Select by file type / invert selection / delete files / empty recycle bin)

________________________________________________
I use this to delete PAR2 and RAR files after downloading from a newsgroup.
- Zaine Ridling, The Great Software blog

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Script for deleting all files except by selected file ty

Post by kiwichick »

Hi there, I'm very new to XYplorer and I understand only very basic scripting. I'm using the latest version of XYplorer and I have tried this script, which might a bit old for my version and may be the reason it isn't working properly. When I run this script I get a message window saying "Nothing to delete". I have tried starting with just the first command adding the rest one at a time. The "select all by filetype" works fine - it still works when I add "invert selection" - but as soon as I add "delete" I get the message window. I've tried creating another script with just the delete command (and all the other possible delete options) but the same thing happens. I'm running Windows 7 Home Premium 64-bit. Cheers from De (making my first post).

zridling wrote:Using the UDC (User-Defined Commands), I've created a simple script from commands and assigned an keyboard shortcut (ALT+6 in my case):
________________________________________________
#254;#252;#169;#642
(Select by file type / invert selection / delete files / empty recycle bin)

________________________________________________
I use this to delete PAR2 and RAR files after downloading from a newsgroup.
Windows 10 Pro 22H2

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script for deleting all files except by selected file ty

Post by TheQwerty »

Give this a try:

Code: Select all

"Delete All but Selected Type(s)"
  #254; // Edit | Select | Select By Selected Type(s)
  Sel 'i'; // Invert Selection
  Delete(0 /*Skip Recycle Bin*/, 1 /*Confirm*/, ':list');
The problem you're seeing is that #169 "File | Delete" works on the selected item(s) in the focused control.
So depending on how you call the script focus might not be in the list pane, and in fact if you weren't so lucky focus could be in the Tree pane causing it to delete the selected folder. :shock:

Another solution would be to force it to focus the list within the script:

Code: Select all

#1016;#254;#252;#169;#642;
//or using the scripting command:
Focus('List');#254;#252;#169;#642;
//(Focus List / Select by file type / invert selection / delete files / empty recycle bin)
Personally, I avoid using command IDs (#252;) when scripting commands (Sel 'i';) are available since it tends to make things easier to understand later. :wink:

kiwichick
Posts: 557
Joined: 08 Aug 2012 04:14
Location: Pahiatua, New Zealand

Re: Script for deleting all files except by selected file ty

Post by kiwichick »

Hey thanks TheQwerty, I barely understood a thing you said now, let alone worrying understanding things later LOL! But I can tell you this works:

Code: Select all

"Delete All but Selected Type(s)"
  #254; // Edit | Select | Select By Selected Type(s)
  Sel 'i'; // Invert Selection
  Delete(0 /*Skip Recycle Bin*/, 1 /*Confirm*/, ':list');
This doesn't - it invokes the same "Nothing to delete" message as before:

Code: Select all

#1016;#254;#252;#169;#642;
This works too:

Code: Select all

Focus('List');#254;#252;#169;#642;
...although I didn't want the 'empty recycle bin' part so I deleted that.

Cheers from De.
Windows 10 Pro 22H2

Post Reply