newbie: windows xp scripting
steve at holdenweb.com
Sun May 21 19:13:38 CEST 2006
> I've been having trouble with the following style of script. It's
> simple stuff, I know, but it's stumping me:
> import os
> dirfrom = 'C:\\test'
> dirto = 'C:\\test1\\'
> copy_command = 'copy "%s" "%s"' % (dirfrom, dirto)
> if os.system(copy_command) == 0:
> print "yay"
> print "boo"
> What's going wrong is with the %s substitution part. I've tried more
> complex scipts and kept running against an error where my script just
> wouldn't work. So I stripped back and back and back to this point,
> where I'm just trying to run a simple copy command. But for some
> reason, it fails.
> If I don't use the %s substitution but use the full pathnames
> explicitly in the copy command, it works fine. So that's where my issue
> seems to be. Help!
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
Type "help", "copyright", "credits" or "license" for more information.
Started with C:/Steve/.pythonrc
>>> import os
>>> dirfrom = 'C:\\Steve\\t1'
>>> dirto = 'C:\\Steve\\t2\\'
>>> copy_command = 'copy "%s" "%s"' % (dirfrom, dirto)
>>> if os.system(copy_command) == 0:
... print 'yay!'
... print 'boo!'
1 file(s) copied.
I don't suppose it's possible your from directory is empty?
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list