-1

I have a program that reads some directories and copies those files to dynamically created. The thing is shutil.copy() keeps failing in some files because they have special characters like ',&,(,),',' so I want to know how to escape them dynamically also. This destination path is created dynamically and just by appending the string, not with any other function or similars.

Ex:

path = "/home/path/ma/gex/%s/%s/%s/" % (d[c][0],d[c2][1].upper(),driveDict[c2][1])

Shutil.copy keeps throwing the exception that the directory doesn't exist, but it's already created, so it can't find the dir. Any help on how to escape this characters or make shutil read them?

EDIT: Files are in a Linux Server, already copied ~10000 files without special chars.

Rg14
  • 300
  • 1
  • 14
  • See http://stackoverflow.com/questions/35817/how-to-escape-os-system-calls-in-python – emnoor Jun 17 '16 at 17:28
  • You should probably use `r"path\file"` I tried copying a txt file using `shutil.copy` and its name has `,` character and it worked. – GIZ Jun 17 '16 at 17:57

1 Answers1

0

There is an encoding problem, just add this two lines to your python code:

# -*- coding: utf-8 -*-
import unicode_literals
khelili miliana
  • 3,730
  • 2
  • 15
  • 28