> what i would like to do it to go all the subdirectories of that home
directory that has many folders and in each folder to create Trash folder
untill it reaches the end of subdirectory
>
> i know it has something to do with a loop statement but can't figure out
on my own or find source on internet
>

Well, without doing *all* of the work for you... =)

There's a handful of ways to go about it, you can use File::Find, which
would make it exceptionally easy, or you can roll it by hand.

File::Find is pretty self-explanatory, so, I'll cover rolling your own.

#!perl

    # get starting dir from command line

my $start_dir = shift;

    # get our initial subdirectories in directory...

my @subdirs = give_dirs($start_dir);

    # while we still have subdirectories...

while($#subdirs >= 0) {

        # create a temp array, for results, here...
    my @temp_dirs;

        # foreach subdirectory we have...

    foreach (@subdirs) {

        print("Found Dir: $_\n");

            # find the subdirs in it, and put them in our
            # temp array

        push(@temp_dirs,give_dirs($_));

            # make your files/dirs, whatever here, too.
        }

        # copy the temp array to our array we check on loop

    @subdirs = @temp_dirs;
    }


sub give_dirs {

 my $dir = shift;
 my @output;

    # opendir

 if(opendir(DIRH,"$dir")) {

        # read files in dir

    my @files = grep(!/^\./,readdir(DIRH));
    closedir(DIRH);

    foreach my $file (@files) {

            # the file name returned from readdir does not
            # include the directory name, we need to add it.

        push(@output, "$dir/$file") if(-d "$dir/$file");
        }
    } else {
        warn("Error: Could not Open Directory $dir -> $!\n");
        return(undef);
        }

        # return list of subdirs.

 return(@output);
}

Enjoy.

!c

C. Church
http://www.digitalKOMA.com/church/
http://www.DroneColony.com/


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to