[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 953
  • Last Modified:

recursive readdir in win32

I need to perform an operation on a directory and its subdirectories in Win32. I thought it would be easy but am having some difficulties. Please provide some generic code. Thanks.
0
Pakfan
Asked:
Pakfan
1 Solution
 
b2piCommented:
my($root) = "C:\\users";
DoDir($root);

sub DoDir {
   my($dir) = shift;
   my($file);
   opendir(DIR, $dir) || die "Unable to open $dir :$!";
   my(@files) = grep {!/^\.\.?$/ } readdir(DIR);
   closedir(DIR);
   foreach (@files) {
      if (-d ($file = "$dir\\$_")) {
           print "Found a directory: $file\n";
            DoDir($file);
      } else {
            print "File $file\n";
      }
   }
}

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now