2

I am trying to copy some_file to another directory (say c:).

Here is my code:

import os
filetest = 'c:\\Documents and Settings\\secret\\Desktop\\testToCopy.txt'
tempdir = 'c:\\'
os.system('copy %s %s' % (filetest, tempdir))

But for some strange reason I always get this answer in response:

The system cannot find the file specified.

2
  • 1
    I suggest removing that os call and using shutil.copy(src, dst) instead. You'll need a import shutil. Doc link Commented Jul 30, 2016 at 23:04
  • Usually arguments containing spaces must be double-quoted. Anyway, you should use shutil interface as suggested by @pie3636 Commented Jul 30, 2016 at 23:06

1 Answer 1

1

As discussed in the comments, you should quote the copy arguments as they may [and in this case do] contain spaces:

os.system('copy "%s" "%s"' % (filetest, tempdir))

As pointed by @pie3636, you should consider using the shutil.copy for that purpose.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.