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

Re: [PBML] Files and Perl for Windows

Expand Messages
  • gordon Stewart
    ... Sorry I dont have Win 2000 - so cant test..:- However this seems to work for me :- my @databack; my @directories; my $datadir= /www/g/my/directory/ ;
    Message 1 of 2 , Dec 1, 2003
    • 0 Attachment
      >From: "Yevgueny" <dneprbeb@...>
      >Reply-To: perl-beginner@yahoogroups.com
      >To: perl-beginner@yahoogroups.com
      >Subject: [PBML] Files and Perl for Windows
      >Date: Mon, 01 Dec 2003 09:19:27 -0000
      >
      >Help me, please, with this small problem. I just want to get a list
      >of files in a directory.
      >
      >opendir (DIR, "C:\\APP");
      >foreach (readdir (DIR)) {
      > print "$_\n";
      >}
      >closedir (DIR);



      Sorry I dont have Win 2000 - so cant test..:- However this seems to work
      for me :-

      my @databack;
      my @directories;
      my $datadir="/www/g/my/directory/";
      opendir(D, "$datadir") or my_die("Error in subroutine backup: can't open
      $datadir", $!);
      push(@databack,readdir(D));closedir(D);
      foreach $line (@databack){
      if ($line !~ m/^\./){
      if (-d $line){
      push (@directories,$line);
      }
      }
      }


      @directories should now contain all file-names - No directories..

      G

      _________________________________________________________________
      Gift-shop online from the comfort of home at MSN Shopping! No crowds, free
      parking. http://shopping.msn.com
    • merlyn@stonehenge.com
      ... gordon my @databack; gordon my @directories; gordon my $datadir= /www/g/my/directory/ ; gordon opendir(D, $datadir ) or my_die( Error in subroutine
      Message 2 of 2 , Dec 1, 2003
      • 0 Attachment
        >>>>> "gordon" == gordon Stewart <gordonstewart5@...> writes:

        gordon> my @databack;
        gordon> my @directories;
        gordon> my $datadir="/www/g/my/directory/";
        gordon> opendir(D, "$datadir") or my_die("Error in subroutine backup: can't open
        gordon> $datadir", $!);
        gordon> push(@databack,readdir(D));closedir(D);
        gordon> foreach $line (@databack){
        gordon> if ($line !~ m/^\./){
        gordon> if (-d $line){

        This isn't testing what you might think it's testing. You're looking
        at the filename (no path component) and asking if it's a directory.
        That's going to look for a file in the *current* directory for the test.
        Not the directory from which you read the name.

        gordon> push (@directories,$line);
        gordon> }
        gordon> }
        gordon> }

        If you're gonna mess with names, use glob(), or understand how
        to prepend the pathname to the results of readdir.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      Your message has been successfully submitted and would be delivered to recipients shortly.