How can I improve the output of the new command folderReport

Discuss and share scripts and script files...
Post Reply
DmFedorov
Posts: 715
Joined: 04 Jan 2011 16:36
Location: Germany

How can I improve the output of the new command folderReport

Post by DmFedorov »

Don made a new folderreport command, but said that improve its output is impossible.
I can convert its output data to the desired view in Notepad++, but I can't do it as a single script.

text folderreport("treeitems:{dir {name}|{name}; {size kbr}; ({modified yyyy-mm.dd_hh:nn:ss});}", "r", , "r");
Current output schema

Code: Select all

                    ··· _Panes
                        ··· 1
                        ··· 1331
                            ··· pane.ini; 5 КБ; (2013-01.08_00:10:44);
                        ··· clone1
                            ··· pane.ini; 13 КБ; (2013-02.13_02:46:58);
                            ··· tab_2.ini; 3 КБ; (2013-01.14_12:55:45);
                        ··· Name_von_Tabsets
                            ··· pane.ini; 33 КБ; (2013-01.28_15:45:20);
                            ··· tab_1.ini; 3 КБ; (2013-01.14_13:21:47);
                            ··· tab_2.ini; 3 КБ; (2013-01.23_05:51:16);
                            ··· tab_3.ini; 3 КБ; (2013-01.23_05:43:09);
                        ··· Nonsense
                        ··· something
My scheme after replacing in notepad++:

Code: Select all

 · · · · · ·\_Panes
 · · · · · · ·\1
 · · · · · · ·\1331
             · pane.ini; 5 КБ; (2013-01.08_00:10:44);
 · · · · · · ·\clone1
             · pane.ini; 13 КБ; (2013-02.13_02:46:58);
             · tab_2.ini; 3 КБ; (2013-01.14_12:55:45);
 · · · · · · ·\Name_von_Tabsets
             · pane.ini; 33 КБ; (2013-01.28_15:45:20);
             · tab_1.ini; 3 КБ; (2013-01.14_13:21:47);
             · tab_2.ini; 3 КБ; (2013-01.23_05:51:16);
             · tab_3.ini; 3 КБ; (2013-01.23_05:43:09);
             · tab_4.ini; 3 КБ; (2013-01.23_04:55:20);
 · · · · · · ·\Nonsense
 · · · · · · ·\something
My actions in Notepad++ (find¦replace¦comment):

Code: Select all

··· ([^;\r\n]*)$¦    \\\1¦one time
(    )¦ ·¦one time
( ·)(\1* ····.*;$)¦  \2¦many times until there will be nothing to replace
···· ¦· ¦one time
Last edited by DmFedorov on 17 May 2016 09:32, edited 1 time in total.

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

Re: How can I improve the output of the new command folderRe

Post by highend »

I don't see a (clever) way to achieve that with regexmatches / regexreplace only (it would need a regex engine that allows to refer to a counted match). In all cases you need a loop and depending on the number of entries in that list it can be a very time consuming process.

The loop needs to check the depth (number of spaces, bullets in front of the first "\" character (for folders) / \w (word character in a regexp)) and depending on if the last depth was lower / higher -> Remove the leading spaces, strrepeat() the new value and prepend them.
One of my scripts helped you out? Please donate via Paypal

DmFedorov
Posts: 715
Joined: 04 Jan 2011 16:36
Location: Germany

Re: How can I improve the output of the new command folderRe

Post by DmFedorov »

highend
Thanks

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

Re: How can I improve the output of the new command folderRe

Post by TheQwerty »

Code: Select all

"Clean report"
  $txt = folderreport("treeitems:{dir ····\{Name}|!{Name};<tab>{Size KBR};<tab>({Modified yyyy-mm.dd_hh:nn:ss});}", 'r',,'r');

  // Replace folder indentations.
  $n = formatlist(regexmatches($txt, '^[ ·]+\\'), 'send');
  foreach ($q, $n, '|', 'e', '') {
    $r = regexreplace($q, '[ ·]{4}', ' ·');
    $q = replace($q, '\', '\\'); //regex-escape
    $txt = regexreplace($txt, "^$q", $r);
  }

  // Replace file indentations.
  $n = formatlist(regexmatches($txt, '^[ ·]+!'), 'send');
  foreach ($q, $n, '|', 'e', '') {
    $r = regexreplace($q, '[ ·]{4}', '  ');
    $r = replace($r, ' !', '· ');
    $txt = regexreplace($txt, "^$q", $r);
  }

  // Remove a level of indentation.
  $txt = regexreplace($txt, '^[ ·]{2}');
  Text $txt;

DmFedorov
Posts: 715
Joined: 04 Jan 2011 16:36
Location: Germany

Re: How can I improve the output of the new command folderRe

Post by DmFedorov »

I thought it was impossible. Thank you very much.

Exactly as I wanted. Thanks again.

Post Reply