Moving around files and fun things of that sort.

Terry Reedy tjreedy at udel.edu
Tue Aug 27 15:43:06 EDT 2002


"Micah Mayo" <astrophels at yahoo.com> wrote in message
news:57e0b28.0208271010.516f2caa at posting.google.com...
...
> respectively. Here is what I'd like to do, basically:
> x = 0
> for x in range (17):
>     os.system('cp -p source[x] destination[x]')
>     if os.path.getsize(source[x]) !=
os.path.getsize(destination[x]):
>         print 'Size not verified, do you wish to contnue?'
>         etc..
>         etc..
> (this is pseudo-code, so don't worry about specific syntax)
> my problem is this will not work with the os.system method. There
> isn't a way that I can find that will allow me to mix these arrays
> with the system command. So a) is there a way for python to copy the
> files w/o using the os.system, or is there a way to make os.system
> work?

You need to construct and pass os.system a string that contains the
names:
something like

for pair in zip(source,destination):
  os.system('cp -p %s %s' % pair)
...

However, you might as well write the file list as one list of pairs in
the first place:

srcdest = (
  (src1, dst1),
...
)

This would be easier to maintain (edit) when list changes.  Then write
for pair in srcdest:
 ...

> Please e-mail me, as I am posting this through google.

OK

Terry J. Reedy






More information about the Python-list mailing list