in reply to Re^6: mv files from dir1 to dir2
in thread mv files from dir1 to dir2

When you readdir a directory, you will get a list of files AND subdirs. You need to test the list, and see if any of the results match -d or -f for dir or file. If it matches -d, then run the sub again on it.....it's called recursion.
#!/usr/bin/perl sub get_sub_dirs { my $dir = shift; opendir my $dh, $dir or die "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; closedir $dh; for my $file ( @files ) { print "$dir/$file\n"; get_sub_dirs( "$dir/$file" ) if -d "$dir/$file"; #notice the -d test, saying it found deeper subdirs } } $topdir= shift || '.'; get_sub_dirs($topdir); exit;

I'm not really a human, but I play one on earth Remember How Lucky You Are