use warnings; use strict; use Cwd; my $cwd = cwd() ; #-- get the subdirs and files opendir ( DIR, $cwd ) || die "$!: dir $cwd doesn't exist!\n"; my @dirs = grep { -d && $_ ne "." && $_ ne ".." } readdir DIR; rewinddir DIR; my @files = grep { -f } readdir DIR; close DIR; $cwd =~ s{/}{\\}g; if ( @dirs ) { $cwd .= '\\'. shift @dirs; } elsif ( @files ) { $cwd .= '\\' . shift @files; } else { $cwd .= '\\.'; } #-- pop the explorer window exec "explorer.exe /e,/select," . $cwd;