smw11 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new to Perl.I need help to write a Perl script to 1.Map a network hidden share like "\\storageshare\project$" 2.Create and write into a simple text file into . 3.and verify the mapped share by disconnect and reconnect again. I am using a windows OS. I have write access to storage hidden share.Any help appreciated. Thank you. smw11

Replies are listed 'Best First'.
Re: How to access Storage hidden share
by NetWallah (Canon) on Jan 24, 2014 at 05:47 UTC
    Welcome to the Monastery!

    Here is an old thread on this subject.

    I'd recommend following Corion's recommendation - there is no need to map a drive in order to create files on the share - just use the UNC path.

    Try just opening the file at the UNC location, and writing to it.

    If you run into trouble, post your code here, (along with how you expect it to behave) and we'll be glad to assist.

            If your eyes hurt after you drink coffee, you have to take the spoon out of the cup.
                  -Norm Crosby

      Hi, Thanks for the information. I have to update perl script for "I" drive mapping. &resetDriveMapping( "I:", $diskArchive ) ; I have to change perl script I map from "\\store\project" to \\store\projectnew$. The new share is hidden format($). I used following function to test the mapping. thank you. smw11
      sub resetDriveMapping { my $isDriveLetter = shift ; my $isSharename = shift ; my $Ifiletest = "$isDriveLetter\\idriveTESTfrom" . $ENV{COMPUTERNA +ME} . ".txt" ; my $Itestmsg = "...resetting: \'$isDriveLetter\' drive mapping fro +m \'$ENV{COMPUTERNAME}\' to \'$isSharename\'" ; &writeLogFile($Itestmsg); my $runCommand = "echo Y|net use $isDriveLetter /DELETE" ; my $retvalue = system($runCommand); if ($retvalue) { &writeLogFile("cannot delete drive $isDriveLetter"); } $runCommand = "net use $isDriveLetter $isSharename" ; $retvalue = system($runCommand); if ($retvalue) { &writeLogFile("cannot map drive $isDriveLetter to $isSharename +"); } #test share mapping $Itestmsg = "...start testing: \'$isDriveLetter\' drive mapping fr +om \'$ENV{COMPUTERNAME}\' to \'$isSharename\'" ; &writeLogFile($Itestmsg); open(ITEST, ">$Ifiletest" ) || &writeLogFile("cannot CREATE $Ifile +test") ; print ITEST "$Itestmsg\n" ; close(ITEST) ; if ( ! -e "$Ifiletest" ) { &writeLogFile("EXITing: test file does not exist \'$Ifiletest\ +'"); exit(0) ; } open(ITEST, "$Ifiletest" ) || &writeLogFile("cannot OPEN $Ifiletes +t") ; my $Itestbuf = "" ; while (<ITEST>) { $Itestbuf = $_ ; } close(ITEST) ; unless ( $Itestbuf ) { &writeLogFile("EXITing: could *not* read test content \'$Ifile +test\'"); exit(0) ; } else { unlink( $Ifiletest ) || &writeLogFile("could not DELETE $Ifile +test") ; &writeLogFile("...end testing: \'$isDriveLetter\' drive mappin +g COMPLETED successfully") ; } }
        I was unable to detect a question or request in your post, so it is difficult to guess what you expect in response.

        You seem to have ignored the advice on avoiding the error-prone drive mapping, (writing directly to a UNC path is the recommended alternative).

        Your code appears to be somewhat fragile, but I suppose it could work.

                If your eyes hurt after you drink coffee, you have to take the spoon out of the cup.
                      -Norm Crosby