select folders with sub-folders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
suslo
Posts: 185
Joined: 02 Feb 2015 05:02

select folders with sub-folders

Post by suslo »

sometimes i have to select folders that contain at least 1 sub-folder
after spending many hours (during several days) on this task, i now have a working script (it uses 1 search template)

the "search templates #264" command contains this template:
- title: keep folders with sub-folders
- find files > name and location > name:

Code: Select all

!. /p /md=1 /matching=e
- applied filters: name
- auto sync: yes
- there are no more ticks in the "name and location" tab

so this is the script:

Code: Select all

 searchtemplate("keep folders with sub-folders", , 8); wait 10; #250; wait 10; #101; wait 10; #485; wait 10; #481; wait 10; selectitems "<clp>", 2
not ideally (and not immediately) but looks like it works

but there are several issues:
- not very big issue: a folder without sub-folders gets selected anyway: in case it contains a file without the dot+extension
- more serious issue: a folder with sub-folders remains unselected: in case it contains 3 (or more) sub-folders with dots in their titles
and i don't understand why does 3 is a problem? (while 2 is not)

is there a better/simplier/more reliable way to select folders that contain at least 1 sub-folder?:
- with 1 click
- without the "dot problem"
- without searching/filtering or paper folders that i don't use
- for example, just like the "select all" command works (immediate and always correct result without flickering)

with no big success i initially tried many various approaches including:

Code: Select all

 $cf = quicksearch("!. /p /md=1 /lpd=1 /matching=e");
 selectitems "$cf";
this variant works but only partially (with small quantity of folders)
the following error appears in case there are ~100 folders: error 6, desc: overflow, proc: script_Process: selectitems
and for example the "/d" never worked as expected (during my attempts)

jupe
Posts: 3577
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: select folders with sub-folders

Post by jupe »

Without trying to decipher your script with all the command IDs, I think basically what you want to do is just select folders which contain at least 1 subfolder in your current path, if I am understanding that correctly, something like this should work:

Code: Select all

selectitems quicksearch("/dp /md=1");

suslo
Posts: 185
Joined: 02 Feb 2015 05:02

Re: select folders with sub-folders

Post by suslo »

it generally works but:
1) i see the same above-mentioned error 6. for instance, in case of 138 folders (all of them have at least 1 subfolder)

2) this script has the same inability (which i saw many times during my attempts) to select all necessary folders in case of the "Program Files" folder: for some reason only first 3 folders (which contain subfolders) get selected
- my "Program Files" folder has 43 subfolders. 30 of them contain 1 or 2 or even 3 dots in a title. example: Every-Thing (1.4.0.703) (Portable)
- it's strange but the "try script" command correctly enumerates the folders that should be selected (but then only first 3 of them become selected)

#250 - select all
#101 - to clipboard (item path, name)
#485 - refresh list
#481 - suspend auto-refresh

jupe
Posts: 3577
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: select folders with sub-folders

Post by jupe »

I haven't encountered any of the problems you have mentioned on my system, but you could try it like this instead:

Code: Select all

  $list = "";
  foreach($curitem, quicksearch("/dp /md=1", , "|")) {
    $list .= gpc($curitem, "file") . "|"; }
  selectitems trim($list, "|");
edit: or maybe even something like this:

Code: Select all

  selectitems replace(quicksearch("/dp /paths=<curpath>\*\ /md=1"), "<curpath>\");
or maybe someone else has a better way...

suslo
Posts: 185
Joined: 02 Feb 2015 05:02

Re: select folders with sub-folders

Post by suslo »

at the moment i see not a single problem with both these codes. i am grateful for your help
if i understand correctly the 2nd variant is preferable

Theodecarvalho
Posts: 49
Joined: 17 Jul 2022 11:59

Re: select folders with sub-folders

Post by Theodecarvalho »

Sorry for newbie question: How can I install this in my XYplorer?

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: select folders with sub-folders

Post by highend »

One of my scripts helped you out? Please donate via Paypal

Post Reply