Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: File Statistics from a shared directory

by Sinistral (Monsignor)
on Aug 06, 2010 at 13:39 UTC ( [id://853407]=note: print w/replies, xml ) Need Help??


in reply to File Statistics from a shared directory

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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://853407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-26 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found