Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: tree command

by Skeeve (Parson)
on Oct 14, 2015 at 06:21 UTC ( [id://1144815]=note: print w/replies, xml ) Need Help??


in reply to Re^3: tree command
in thread tree command

Okay. So would you mind telling me how I could filter out:

  • hidden files and directories (okay - "glob")
  • files

without iterating over the content of the directory and know in advance that the last 3 items in my list don't count?

Example: I have in my list [ a b c d e ] where b, d and e are files, which I do not want to display, while a and c are the directories to show. How would I know that in advance?

With my approach I filter b, d and e out, leaving me with just [ a c ]. So I know that after "c" there won't be any more files or directories to be displayed.

How would you achieve this?


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^5: tree command
by choroba (Cardinal) on Oct 14, 2015 at 09:45 UTC
    You can use
    my @dirs = glob '*/';

    To get the number of files, just subtract the number of dirs from the number of everything.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Which will iterate of the files a second time and will access the file system while I iterate over an array. Or am I wrong?


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
        Ouch, you're right. Doing -f wouldn't help much, either. What about
        my @all = glob '* */'; @dirs = grep m(/$), @all; # etc.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^5: tree command
by RichardK (Parson) on Oct 14, 2015 at 09:17 UTC

    Doesn't the code I posted do exactly that with only one pass? I didn't add the display file bit, but that's trivial to add if you need it.

    Here's the output of my code run on my junk directory, it seems to do what you ask :)

    +-dbf +-palindrome +-plot +-rules | +-abc1 | | +-ba | | +-de | | +-te

      if you didn't just post a part of the output, my tree would look like this:

      . \--dbf |--palindrome |--plot \--rules \--abc1 |--ba |--de \--te

      You see? I need to know, when I'm at "dbf", "rules", "abc1" and "te", that this one is the last element in the respective directory to stop printing the superfluous "|" characters you have.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1144815]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-28 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found