ikegami,

Your first example (changing the current drive only) looks good, but I'm not sure your second example (changing the current directory of a drive):

my $drive = substr(getcwd(), 0, 2); chdir('C:\\'); chdir($drive);

quite works.

Yes, it will work if you're going to the top-level directory "\", (for which you could do the simpler chdir('C:/')) but if you need to change to a directory on (for example) drive D: which doesn't exist on drive C:, then changing to C:\dir_on_drive_d will fail:

use strict; use warnings; use Cwd qw(getcwd chdir getdcwd); # Here, D:\testdir exists, but C:\testdir does NOT my $drive = substr(getcwd(), 0, 2); chdir('C:/testdir') or die "No such directory 'C:/testdir'\n"; chdir($drive); __END__ Produces: No such directory 'C:/testdir'

How about just using the drive and directory together, which seems to work okay:

use strict; use warnings; use Cwd qw(chdir getdcwd); show_drives(); system("dir/w"); chdir("D:/testdir") or die "Can't change to dir 'D:/testdir' ($!)\n"; system("dir/w"); sub show_drives { printf "You are in '%s' on the current drive\n", getdcwd(); printf "You are in '%s' on the 'D' drive\n", getdcwd('D'); print "\n"; }

which correctly displays the contents of D:\testdir after the command chdir("D:/testdir"):

You are in 'C:\Documents and Settings\liverpole\perl' on the current d +rive You are in 'D:\testdir' on the 'D' drive Volume in drive C has no label. Volume Serial Number is E451-D99E Directory of C:\Documents and Settings\liverpole\perl [.] [..] dirtest.pl dirtest.pl~ 2 File(s) 836 bytes 2 Dir(s) 10,946,477,056 bytes free Volume in drive D is WIN2000 Volume Serial Number is EEE2-EEE2 Directory of D:\testdir [.] [..] a.txt b.txt c.txt 3 File(s) 24 bytes 2 Dir(s) 3,777,839,104 bytes free

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re^6: Bugs in File::Find on Windows by liverpole
in thread Bugs in File::Find on Windows by jdporter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.