[python-win32] Mapping Drives in Python
Becky Mcquilling
ladymcse2000 at gmail.com
Fri Mar 4 08:46:04 CET 2011
Hi:
Hoping you guys can help out a python noob here.
I have a list of machines that I am backing up flat files from to one
central machine. I need to:
a) Map Drives and b) run robocopy
I am iterating through a text file that has the share names and the and
directory that I want to be created:
count = 0
alphabet = 'klmnopqrstuv'
today = datetime.date.today()
backup_servers = {}
f = open('c:/test/backup_shares.txt')
for line in f:
backup_server = line.split(',')
backup_servers[ backup_server[0]]=backup_server[1]
for i, v in backup_servers.items():
backup_shares = i
archive_dir = v.strip()
archive_dir += str(today)
drive_letter = alphabet[count]
count += 1
The above creates a dictionary and I iterate through that.
backup_shares = '\\server_name\c$' for example and archive_dir is the
directory on the local machine that I will create with a timestamp to backup
the files to on the local machine example "d:\backup_dir\03-03-2011\files
What I want to do is map a drive, which is why the alphabet string. I
iterate through that and then get k first backup dir, etc.
I'm not sure what method to call to map a drive or how the best way to call
robocopy is. I don't have the choice of using IronPython. I have the win32
modules.
And this works:
win32net.NetUseAdd(None,1,{'remote':r'\\server_name\c$','local':'K:'})
However, I want to use the variable backup_server and insert the
drive_letter variable in the script snippet, but I haven't been able to make
that work. Any suggestions?
Also, suggestions and examples on calling robocopy?
Thanks so much!
Becky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110303/8dd0aa46/attachment-0001.html>
More information about the python-win32
mailing list