0

shutil.copytree()当文件名中有空格时我不能使用。我想我必须使用原始字符串 -->r'your-string' 但是如何实现呢?

编辑:这是我的代码。

import os
import shutil
import sys

usb_folder = os.listdir("/media/kame")

# create path       okay
path_ = r'/media/kame/' + str(usb_folder)[2:-2]

# copy files
path_2 = path_ + '/main'

#try:
#    os.makedirs(path_2)
#except:
#    pass

shutil.copytree('/home/kame/Desktop/main/bilder/geschichte',path_2)

这是错误:

File "/usr/lib/python2.7/shutil.py", line 208, in copytree
    raise Error, errors
    shutil.Error: [('/home/kame/Desktop/main/bilder/geschichte/Screenshot from 2014-12-24 11:09:06.png', '/media/kame/INTENSO/main/Screenshot from 2014-12-24 11:09:06.png', "[Errno 22] invalid mode ('wb') or filename: '/media/kame/INTENSO/main/Screenshot from 2014-12-24 11:09:06.png'"), ('/home/kame/Desktop/main/bilder/geschichte/Screenshot from 2014-12-22 21:41:28.png'
4

1 回答 1

0

它适用于:

distutils.dir_util.copy_tree('/home/kame/Desktop/main', path_2)

但为什么shutil.copytree()不起作用?

于 2014-12-31T12:47:26.270 回答