my $drive = substr(getcwd(), 0, 2);
chdir('C:\\');
chdir($drive);
####
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'
####
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";
}
####
You are in 'C:\Documents and Settings\liverpole\perl' on the current drive
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