I want to test if I can write to a mapped drive. The code below does this by simply:
1 seeing if –d test means the drive can be seen;
2 trying to open a ‘test’ file and write one word.
use strict "vars";
my ($map_letter, $en_num, $en_mes, $net_file, $res_open);
$map_letter = "H:\\";
if(-d $map_letter) {
$net_file = ">" . $map_letter . "netfile.txt";
$res_open = open(NETOP, $net_file);
if($res_open == 1) {
print NETOP "Hello\n";
close(NETOP);
print "netfile print OK\n";
} else {
$en_num = Win32::GetLastError();
$en_mes = Win32::FormatMessage($en_num);
print "netfile print failed number <$en_num>\nmessage <$en_mes
+>\n";
}
} else {
$en_num = Win32::GetLastError();
$en_mes = Win32::FormatMessage($en_num);
print "could not find mapped drive <$map_letter>\nnumber <$en_num>
+\nmessage <$en_mes>\n";
}
I wondered if there was a more elegant way:
1 where I could find out what the mapped drive was set to;
2 to tell if the drive was shared in a way that I could write the file.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.