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

Re: Create a list of directories without . and ..

by BrowserUk (Pope)
on Jun 04, 2002 at 18:52 UTC ( #171599=note: print w/replies, xml ) Need Help??

in reply to Create a list of directories without . and ..

Being unsure of the etiquette here, I am not sure if "thankyou"s are in order (but no doubt someone will tell me...:)

So, until that piece of enlightenment comes my way... Thankyou!!

Living in darkness; seeking the light; Weak, but will be strong with the help of the Brothers

  • Comment on Re: Create a list of directories without . and ..

Replies are listed 'Best First'.
Re: Re: Create a list of directories without . and ..
by 914 (Pilgrim) on Jun 04, 2002 at 19:16 UTC
    you can also use File::Find (as i've recently found)

    something like: (i've not tested this!)

    my @found; File::Find::find({wanted => \&wanted], '.'); sub wanted { if (-d $_) && ($_ != '.') && ($_ != '..') { push(@found, $_) } }
    sure, this is not the fastest way (someone on the above referenced node timed the native find vs File::Find, with native winning by a factor of 5), but it's a way.

    also, be careful of the greps to remove the . and .. entries... it's legal to have directories that start with a period (or two, or more), so you have to do an exact match on both cases.

    (i think)

    i too am a newbie here, and i've been thanking people...
    hopefully, i can provide some answers myself one day.

    (ps: please forgive the expanded syntax, but it's (to my unPerlish eye) easier to read!)

      You are correct about . and .. - getting a regex to match them reliably is far trickier than it looks. The obvious m/^\.\.?$/, for instance, will give a false positive on "..\nsubdir". Much safer and simpler to just test on ($_ ne '.') && ($_ ne '..'). (BTW, != is numeric. Use ne for strings.)

        The obvious m/^\.\.?$/, for instance, will give a false positive on "..\nsubdir"

        No, only on "..\n" and ".\n".

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.

      if (-d $_) && ($_ != '.') && ($_ != '..') {

      This is invalid syntax (needs an extra set of parens) and the != operator is not the one you want for string equality tests. I think you meant:

      if (-d and $_ ne '.' and $_ ne '..') {
      -d uses $_ if no argument is given.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.

        Hi. Still having trouble with this...I do not understand why calling " ." finds subdirs in the Products subdir if I run it there and pass "." as the arg but doesn't find them if I run it one level back (ie. CD ..)and pass "./Products" as the arg??

        This is true which ever of the two filter clauses I use.

        I hate being a "newbie" again.

        C:\www\\html>type #!/usr/bin/perl -w use strict; use diagnostics; print $ARGV[0], "\n"; opendir(DIR, $ARGV[0] ) or die ".: $!"; #my @list = grep { -d and /^\.\.?/ } readdir(DIR); my @list = grep { -d $_ and $_ ne '.' and $_ ne '..'} readdir(DIR); closedir(DIR); print foreach ( @list ), "\n"; C:\www\\html> . . cssgraphicsProducts C:\www\\html> ./products ./products <<<< NO OUTPUT HERE??? C:\www\\html> ./Products/ ./Products/ <<<< OR HERE???? C:\www\\html>cd products C:\www\\html\Products>../ . . Books C:\www\\html\Products>
        Thanks, NJ Sandever.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://171599]
[Corion]: choroba: I'm still using spod5 as my pod-to-ooxml- converter didn't really get off the ground so far
[choroba]: Slidy is basically HTML, so I'm not sure I really fly high :)
choroba should make his presentation scaffolding public
[Corion]: choroba: spod5 converts pod to S5 HTML, so it's also still basic. I find the lack of animations (in the sense of "highlight this", "highlight that" in code) somewhat tedious as I do it with rendered PNGs
[Corion]: I haven't found a good way to include/use the source SVGs I use for creating the PNGs directly as animations
[ambrus]: Presentations come in many different shapes, and so slides do as well.
[Corion]: Doing that in Powerpoint or Ooxml would be nice(r) but I'm much quicker doing the outline of a presentation and the code as Pod
[Corion]: Hurrr - on a machine that is behaving weirdly, I have two processes CROND running. I guess that is the source of unattended jobs sometimes not finding their files anymore...
[ambrus]: Most of the time if I make slides, they're just a formatted document with a medium level of formality (between a well written article and an informal draft), with usually the page breaks chosen carefully and possibly some content repeated between pages.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-09-26 10:04 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.