0

I can't use shutil.copytree() when there are whitespaces in the filename. I think I have to use the raw string --> r'your-string' But how to implement this?

EDIT: This is my code.

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)

And this is the Error:

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'
kame
  • 20,848
  • 33
  • 104
  • 159

1 Answers1

-1

It works with:

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

But why shutil.copytree() doesn't work?

kame
  • 20,848
  • 33
  • 104
  • 159