Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Get list of first level subdirectories

by socketdave (Curate)
on Jul 21, 2005 at 14:14 UTC ( [id://476841]=note: print w/replies, xml ) Need Help??


in reply to Get list of first level subdirectories

This code lists directories in the current directory, and child folders one level down. I'll leave it to you to make this delete your files ;) (btw, this is pretty much straight out of the black leopard book)
#!/usr/bin/perl -w use strict; use Cwd; sub ScanDirectory{ my ($workdir) = shift; my ($depth) = shift; $depth++; my ($startdir) = &cwd; chdir($workdir) or die; opendir(DIR, ".") or die; my @names = readdir(DIR) or die; closedir(DIR); foreach my $name (@names) { next if ($name eq "."); next if ($name eq ".."); if (-d $name) { print &cwd."/".$name."\n"; &ScanDirectory($name, $depth) if $dept +h <= 1; next; } } chdir($startdir); } &ScanDirectory(".",0);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found