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

Re: Directory Parsing

Expand Messages
  • Yogesh Sawant
    ... files. ... Here is the script that will differentiate between files and directories: #!/usr/bin/perl opendir DIR, . ; @files = grep {!/^ ./} readdir(DIR);
    Message 1 of 3 , Jun 26, 2006
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "Jason Benjamin"
      <red_hax0r@...> wrote:
      >
      > I came up with this small script that will read all non-hidden
      files.
      > But I can't figure out how to set it up so that that it
      > differentiates between directories and files.
      >
      >
      > #!/usr/bin/perl
      > opendir DIR, ".";
      > @files = grep {!/^\./} readdir(DIR);
      > closedir DIR;
      > print map { "$_\n" } sort @files;
      >
      > #any ideas?
      >

      Here is the script that will differentiate between files and
      directories:

      #!/usr/bin/perl

      opendir DIR, ".";
      @files = grep {!/^\./} readdir(DIR);
      closedir DIR;

      foreach my $file (@files) {
      if (-d $file) {
      print "Directory: $file \n";
      }
      else {
      print "Non-Directory: $file \n";
      }
      }

      Cheers
      Yogesh
    Your message has been successfully submitted and would be delivered to recipients shortly.