http://qs321.pair.com?node_id=541864

Even though I'm on Windows, I like to use the command line as much as possible. For example, I like to be able to pop a DOS box from right-clicking on a directory in Windows Explorer (see this registry hack).

The reverse of this is to open Windows Explorer from the command line of the DOS box, and have it set to the current directory of the DOS box. The following script formats the call to Explorer's command line arguments to do that. It attempts to highlight the first file or subdirectory in the directory specified. The only bug I have so far is that if you are in an empty directory, Explorer doesn't open the directory for you.

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;
Extract the file to expl.pl in your PATH and invoke with

>expl