Copying files to multiple comp's on a lan
Jeff Shannon
jeff at ccvcorp.com
Fri Jun 1 20:06:02 EDT 2001
Hm, I'd probably use the os.system() call in preference to reading the
source and then creating new destination files, as D-Man's example does,
though the choice is probably trivial and entirely personal opinion.
Example:
---------------------
import sys
import os
# note Win32 uses \, not / :)
machines = [ "\\Mach1\C" , "\\Mach2\C" , "\\Mach3\C" ]
source_file_path = sys.argv[1]
dest_path = sys.argv[2]
for machine in machines:
# always use os.path.join() when building paths....
dest_fullpath = os.path.join(machine, dest_path)
cmd_string = "copy %s %s" % (source_file_path, dest_fullpath)
os.system(cmd_string)
---------------------
You'd probably be better off if the machine/drive specs were built using
the functions in os.path as well, but that's a minor detail. I'd also, if
I were writing this script for my own use, add a few print statements to
report on the current status, etc.... I'd also probably put the os.system()
call within a try/except block, just in case. And of course, this all
presumes that you do have write permission on all of these machines. :)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list