所以我在目录中有这些文件:
file1.txt
demo.py
然后我运行以下代码(demo.py):
import os
os.system("copy file1.txt file2.txt")
但是我明白了:
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
The system cannot find the file specified.
一点。如果我这样做
copy file1.txt file2.txt
在命令提示符下-运行正常。这是怎么回事?在Windows上使用os.copy时,我需要完全引用该文件吗?
答案 0 :(得分:0)
os.system()执行Shell命令。试试这个:
import subprocess
cmd = "copy file1.txt file2.txt"
execute = subprocess.call(cmd, shell=True)
print('output', execute)