title: How to traverse all the files in a directory; if it has subdirectories, I want to traverse files in subdirectories too
body: <pre><code>opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
      my @files = readdir(DIR);
      closedir(DIR);
      foreach my $file (@files) {
          next if ($file !~ /\.txt$/i);
          my $mtime = (stat($file))[9];
          print $mtime;
          print "\n";
      }
  </code></pre>
  
  <p>Basically I want to note the timestamp of all the txt files in a directory. If there is a subdirectory I want to include files in that subdirectory too.</p>
  
  <p>Can someone help me in modifying the above code so that it includes subdirectories too.</p>
  
  <p>if i am using the code below in windows  iam getting timestamps of all files which are in folders even outside my folder</p>
  
  <pre><code> my @dirs = ("C:\\Users\\peter\\Desktop\\folder");
      my %seen;
      while (my $pwd = shift @dirs) {
              opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
              my @files = readdir(DIR);
              closedir(DIR);
              #print @files;
              foreach my $file (@files) {
                      if (-d $file and !$seen{$file}) {
                              $seen{$file} = 1;
                              push @dirs, "$pwd/$file";
                      }
                      next if ($file !~ /\.txt$/i);
                      my $mtime = (stat("$pwd\$file"))[9];
                      print "$pwd $file $mtime";
                      print "\n";
              }
      }
  </code></pre>