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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|