我想複製我的Automater工作流程,我已將它們列在配置文件中,並且我想循環訪問配置文件並複製目錄。他們的名字中有空格,我遇到了麻煩。我在複製目錄時遇到了問題
它正確等打印的文件名,但複製失敗,因爲似乎是多餘的「」周圍的名稱與副本
import os
import shutil
confdir=os.getenv("my_config")
dropbox=os.getenv("dropbox")
conffile = ('services.conf')
conffilename=os.path.join(confdir, conffile)
sourcedir= (r'~/Library/Services/')
destdir=os.path.join(dropbox, "My_backups")
for file_name in open(conffilename):
sourcefile=os.path.join(sourcedir, repr(file_name.strip()))
print sourcefile
destfile=os.path.join(destdir, file_name.strip())
shutil.copytree(sourcefile, destfile)
和錯誤是提前
~/Library/Services/'Add PDF Metadata.workflow'
Traceback (most recent call last):
File "Untitled 3.py", line 15, in <module>
shutil.copytree(sourcefile, destfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 168, in copytree
names = os.listdir(src)
OSError: [Errno 2] No such file or directory: "~/Library/Services/'Add PDF Metadata.workflow'"
謝謝
我已經嘗試了下面的建議,但它仍然不起作用
我設法解決這一切在這裏 http://stackoverflow.com/questions/13052341/i-seem-to-get-an-error-although-the-script-runs-i-cant-看到爲什麼 – geekcomputers