Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] opendir readdir

Expand Messages
  • Adrian Stovall
    ... The . directory is a sysnonym for whatever directory you are currently in. The .. directory is a synonym for the parent directory of
    Message 1 of 3 , Nov 29, 2002
    • 0 Attachment
      <snip>
      >
      > hello
      >
      > i have a directory that contains 2 directories
      > which each contain textfiles
      >
      > when i use data::dumper to see then i get these
      > directories and files called '.' and '..' which are actually not there
      >
      > does anybody know what they are and how i can avoid them ?
      >
      > thanks
      > git
      >
      > #!C:\perl\bin\perl.exe -w
      > use strict;
      > use Data::Dumper;
      >
      > my $path = 'C:/path/path/';
      >
      > opendir( DIR, "$path" ) || die " not found";
      > my @array = readdir DIR;
      > closedir DIR;
      >
      > my %dir;
      >
      > foreach my $thedir(@array){
      > opendir (DIRO, "$path/$thedir") || die " not found ";
      > my @list = readdir DIRO;
      > closedir DIRO;
      > $dir{$thedir} = \@list;
      > }
      >
      > print Dumper( \%dir);
      </snip>

      The . directory is a sysnonym for whatever directory you are currently
      in. The .. directory is a synonym for the parent directory of whatever
      directory you're currently in. These *are* directories, but not ones
      that you'd typically use in a directory-parsing routine.

      To exclude them, wrap a little conditional statement around the contents
      of your directory-opening loop (untested...play around with the
      concept). Just check for one or two dots (I cheated and just looked for
      directory entries that are ALL dots...could have more than 2), and skip
      entries that match those criteria...

      foreach my $thedir (@array){
      unless ($thedir =~ /^\.+$/) {
      opendir (DIRO, "$path/$thedir") || die " not found ";
      my @list = readdir DIRO;
      closedir DIRO;
      $dir{$thedir} = \@list;
      }
      }


      perl -e "sub Sub{return reverse(@_);}$i='ohce';$_='.$yyye k ca i Xl$yyye
      jX $yyyehto ZfX tq $uQ';s+[
      \$]++g;s-j-P-;s^yyy^r^g;s:i:H:;s!X!!g;s|Z|n|;s*Q*J*;s{q}{s}g;s(f)(A);sys
      tem(join('',Sub(split('',$i))),(join('',Sub(split('')))));"

      To the optimist, the glass is half full.
      To the pessimist, the glass is half empty.
      To the engineer, the glass is twice as big as it needs to be.

      Adrian "Okay, I won't top-post unless it's an emergency" Stovall
    Your message has been successfully submitted and would be delivered to recipients shortly.