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

Hi Monks, Need your wisdom again.

I am trying to connect to a shared folder on a windows machine. Could you let me know how can I map the shared folder to a drive, I tried using win32::fileop module but was not successful in mapping the drive.

Once I connect to the shared directory I want to get the timestamp of the file for some logging purposes. Please let me know how we can acheive this.

Thanks in advance. Regards, Ravi.
  • Comment on File Statistics from a shared directory

Replies are listed 'Best First'.
Re: File Statistics from a shared directory
by Sinistral (Monsignor) on Aug 06, 2010 at 13:39 UTC

    For the first part of your program, you can use the Windows net use command. In Perl, you'll want to use the system() function to do your work:

    $returncode = system("net use Z: /USER:domain\\username \\\\computerna +me\sharename password");

    Note that you could ask the user in your Perl script for the password so that you don't have to have the password hard coded in your Perl code. Then you would put your password variable (perhaps $password) in place of the hard coded string password. Because I'm using double quotes (which in Perl means to interpolate) I have had to double the backslashes to indicate that I want actual backslashes. If you change the quotes to single quotes and hard code the password you would only need 1 backslash for every two I show in the code. You also don't have to have a domain for the /USER flag. The Z: is the drive letter you want to map, and can be any unused letter on the computer

    I don't show it, but you'll want to check the return code to make sure your net use succeeded, or attempting to access the files won't work

    You can get file information on individual files by using the stat() function and passing the path to the file name (said path would include the newly mapped drive letter).