1

I have a problem, which I can't deal with. I'm trying to make my own program to send files to Dropbox, but their system doesn't allow backslashes.

When I want to send path to file like this:

..\Users\TS\Desktop\Program\Nowy dokument tekstowy - Kopia (2).txt

I got error:

ErrorResponse: [400] {u'path': u"Invalid path '/..\\Users\\TS\\Desktop\\Program\\Nowy dokument tekstowy - Kopia (2).txt': character at index 3: backslash not allowed"}

I googled for this (i.e. here and here), searched in Python's os.path docs but it didn't help me.

I mean output for this code:

s = r'..\Users\TS\Desktop\Program\Nowy dokument tekstowy - Kopia (2).txt ' s.replace('\\', '/') print s

or this:

s = r'..\Users\TS\Desktop\Program\Nowy dokument tekstowy - Kopia (2).txt ' s.replace('\\', '/') print s

is the same:

..\Users\TS\Desktop\Program\Nowy dokument tekstowy - Kopia (2).txt

I need to deal with relatives paths, not absolutes. Any other idea how to deal with paths like this? Or maybe how to make Dropbox accepts backslashes?

EDIT: I'm using Python2.7

Community
  • 1
  • 1
Szkaplerny
  • 49
  • 3
  • 11

1 Answers1

1
s = r'..\Users\TS\Desktop\Program\Nowy dokument tekstowy - Kopia (2).txt '
s = s.replace('\\', '/')
print s

Output: ../Users/TS/Desktop/Program/Nowy dokument tekstowy - Kopia (2).txt

Note that s.replace() by itself doesn't do anything. You have to assign s = s.replace() to have the desired effect.

Navin
  • 3,681
  • 3
  • 28
  • 52