Copying files to multiple comp's on a lan

D-Man dsh8290 at rit.edu
Fri Jun 1 22:07:54 EDT 2001


On Fri, Jun 01, 2001 at 05:06:02PM -0700, Jeff Shannon wrote:
| 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.

There is a bit of technical tradeoff in the choice when using
Windows see below.

| Example:
| 
| ---------------------
|  import sys
|  import os
|  
|  # note Win32 uses \, not /  :)

Yeah, but ...

|  machines = [ "\\Mach1\C" , "\\Mach2\C" , "\\Mach3\C" ]

>>> print machines
['\\Mach1\\C', '\\Mach2\\C', '\\Mach3\\C']
>>> print len( machines[0] )
8  
# wasn't that supposed to be 9?  and where'd that extra \ in front of
# the C come from?

backslashes are rather evil -- they tend to undergo a bit of
metamorphosis in various environments...

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

Also, make sure that what cmd.exe sees here is what you expected (with
backslashes, spaces, etc.


I have no philosophical issues with this sort of technique, though
I've been bitten by the evil M$ backslashes a few times with my shell
scripts (where one script invokes another, and yet another layer of
backslash escaping is evaluated away).  I once had to label a printer
as \\\\\\\\Red1\\\\HPLaserJ (!) //Red1/HPLaserJ works much better :-).
If fact the bash script I included used the 'cp' command (the cygwin
binary of the unix command, roughly equivalent to copy.exe).

On the tutor list Tim Peters enlightened us to one of M$'s deepest
secrets -- the win32 API accepts forward slashes as a path delimiter.
I was rather relieved to learn that this (often) works from the shell
as well (bash, anyways, cmd.exe still tends to not like it).  Using
forward slashes saves a lot of headaches.

-D





More information about the Python-list mailing list