Page 1 of 2
Branch view with files and parent folders only
Posted: 20 Dec 2020 23:55
by LittleBiG
Is it possible to create a branch view which contains specific files ?*.txt /flat and only the folders which contain this txt files? The tree like structure could look much better with parent folders but I couldn't find a way to show them. All I could do is extend the quick search with all folders by ?*.txt or attr:d /flat but I wouldn't need the ones without any txt files.
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 00:27
by highend
Don't know if this is possible...
Have you tried to use a paperfolder instead (adding the path column would be necessary)?
Like:
Code: Select all
$tmpFile = "%TEMP%\~XYPaperfolder.txt";
paperfolder("Test", quicksearch("*.txt /f"), , "nl");
columnlayout($tmpFile, "save");
$content = readfile($tmpFile);
if (regexmatches($content, "(^|,)Path\.")) {
$content = regexreplace($content, "(^|,)Path\.", "+Path.");
writefile($tmpFile, $content, , "tu");
columnlayout($tmpFile);
}
sortby "Path", "a", 0;
sortby "Name", "a", 1;
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 00:37
by jupe
If I am understanding you correctly, you should be able to do it, but it would involve doing 2 searches, so would probably be easier if invoked via a script, below is a quick mock up of what I mean:
Code: Select all
$folder = "C:\test";
$find = "*.txt";
$results = quicksearch("$find /f ", $folder) . <crlf>;
$results .= quicksearch("$find /fp", $folder);
paperfolder("Test", $results,, "n");
tab("new", "paper:Test?/hn /flat");
sortby "Path", "a";
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 19:15
by LittleBiG
Thanks highend and jupe, both solutions are instructive. The second one is a bit closer what I wanted to achieve, the only problem that the parent folders are "hanging" in the air, so if a folder is in the list because it is a parent, the whole branch should be shown to make it visually better.
In other words, when the txt files and all folders are displayed, the leaves without txt files in it should be removed.
Test folder, txts with all folders:
2020-12-21_19h09_11.png
Jupe's solution:
2020-12-21_19h09_58.png
Desired outcome:
2020-12-21_19h11_15.png
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 19:51
by LittleBiG
If I put the txt to another folder, it is even more spectacular:
2020-12-21_19h46_43.png
2020-12-21_19h47_30.png
Actually, I am not sure why this interpretation is missing from the XY possibilities. It looks so natural.
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 19:55
by jupe
Something like this should work then, you may want to optimize it, this is just a quick modification of the previously supplied script that I think should be close to your needs, or give you the idea of 1 way how to achieve what you require, it'll probz need customizing depending on how many nested levels you intend on using it with regularly, or you can add code to count through them in the script.
Code: Select all
$folder = "c:\test";
$find = "*.txt";
$results = quicksearch("$find /f", $folder,, "s") . <crlf>;
$resFol = quicksearch("$find /fp", $folder);
foreach($fol, $resFol, <crlf>, "e") {
$results .= gpc($fol, "component", -2, 1) . <crlf>;
$results .= gpc($fol, "component", -3, 1) . <crlf>;
}
$results = formatlist($results . $resFol, "des", <crlf>);
paperfolder("Test", $results,, "n");
tab("new", "paper:Test?/hn /flat");
sortby "Path", "a";
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 21:34
by LittleBiG
Thanks for the the script, I was uncharacteristically clueless on this. My only work now is coding the last step.
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 22:45
by LittleBiG
OK, it is ready. I replaced gpc() commands with a while loop, practically that was it. Thanks again!
I put the whole script here, just not to let things half done.
Code: Select all
end (strpos(tab("get", "path"), "paper:") != -1), "Can't be executed in a paperfolder view!";
$folder = "<curpath>";
$find = "*.txt";
$papername = "Custom Branch View";
$results = quicksearch("$find /f", $folder,, "s") . <crlf>;
$resFol = quicksearch("$find /fp", $folder);
foreach($fol, $resFol, <crlf>, "e") {
$count = -1;
while (gpc($fol, "component", $count, 1) != $folder) {
$results .= gpc($fol, "component", $count--, 1) . <crlf>;
}
}
$results = formatlist($folder . <crlf> . $results, "des", <crlf>) ;
paperfolder($papername, $results,, "n");
tab("new", "paper:$papername?/hn /flat");
sortby "Path", "a";
EDIT: I edited the script because I put the main folder to the top of the view, I like it better this way.
EDIT2: I have just listed the exe files in the Program files then in my Portables folder. Very cool! I am sure it would deserve being among the core functions of BV.
EDIT3: extended with highend's preventive measure to avoid XY being frozen
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 23:16
by highend
You should make sure that you don't execute that script again while in that paperfolder view...
E.g.:
Code: Select all
end (strpos(tab("get", "path"), "paper:") != -1), "Can't be executed in a paperfolder view!";
Re: Branch view with files and parent folders only
Posted: 21 Dec 2020 23:34
by LittleBiG
highend wrote: ↑21 Dec 2020 23:16
You should make sure that you don't execute that script again while in that paperfolder view...
E.g.:
Code: Select all
end (strpos(tab("get", "path"), "paper:") != -1), "Can't be executed in a paperfolder view!";
Indeed, thanks! I did manage to make XY frozen accidentally during the testing because of this, but I was too tired to come up with something. It is almost midnight here.
Re: Branch view with files and parent folders only
Posted: 22 Dec 2020 17:34
by LittleBiG
Much ado about nothing. The solution worked only because of a bug, and I was stupid enough to drive the attention to it accidentally.
Re: Branch view with files and parent folders only
Posted: 22 Dec 2020 17:36
by highend
At least it was a nice bug^^
Re: Branch view with files and parent folders only
Posted: 22 Dec 2020 17:37
by LittleBiG
highend wrote: ↑22 Dec 2020 17:36
At least it was a nice bug^^
Indeed. A lady bug.
Re: Branch view with files and parent folders only
Posted: 22 Dec 2020 20:00
by LittleBiG
My last idea was to collect the folders which shouldn't be shown, but when I passed the list to the /excl= switch, the folders didn't disappear. Also, I couldn't come up with a visual filter either. Total failure.
Re: Branch view with files and parent folders only
Posted: 22 Dec 2020 22:21
by highend
It is possible if you really want it...
Code: Select all
$searchPath = <curpath>;
$findPattern = "*.txt";
$matches = quicksearch("$findPattern /f", $searchPath, , "s");
if (trim($matches, <crlf>) == "") { status "No match(es) found, aborted!", "8B4513", "stop"; end true; }
$noMatchDirs = quicksearch("$findPattern /fx", $searchPath, , "s");
$cntNoMatchDirs = gettoken($noMatchDirs, "count", <crlf>);
// Test if a "no-match dir" can be found in $matches
// and if NOT, put it on the $ghostFilter list
$ghostFilter = "";
while ($i++ < $cntNoMatchDirs) {
status "Processing $i / $cntNoMatchDirs", , "progress";
$noMatchDir = gettoken($noMatchDirs, $i, <crlf>);
if (strpos($matches, $noMatchDir) == -1) {
$ghostFilter .= $noMatchDir . "|";
}
wait 1;
}
// # (digit) and [ (beginning of a range) must be escaped for ghost()
if ($ghostFilter) { ghost(regexreplace($ghostFilter, "(#|\[)", "[$1]"), 1); }
// Branch view in new tab
tab("new", "$searchPath?$findPattern /h /flat");
sortby "Path", "a";
msg "Don't forget to turn the ghost filter off!", 64;
But beware, you need to turn off the ghost filter afterwards^^
You are free to remove the status report and the wait command, but you can't interrupt it anymore afterwards
and please don't try this on "C:\Windows", it would take ages (I see no clever way to reduce the number
of comparisons atm)...