Cannot open file because of its name

Viewed 235

I am trying to rename some files and I had a problem with some of them. I'll give an example: I tried to rename a file with the name "pronunciation_he_ אָדוֹם_אֲדוּמָה". It gave me an error and when I looked deeper into it, I figured out that it is because it can't open the file. The problem is not with the hebrew charaters but with the weird space. When I change the space to a normal space everything worked fine.

I am using python 2.7.15.

This is the code that changes the names of the files:

import os
for filename in os.listdir("E:\Project\Selenium\Check"):
    os.rename(os.path.join("E:\Project\Selenium\Check" ,filename), os.path.join("E:\Project\Selenium\Check" ,"check.mp3"))

The error: WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect

When I just tried opening the file:

import os
for filename in os.listdir("E:\Project\Selenium\Check"):
    file = open(os.path.join("E:\Project\Selenium\Check" ,filename))

The error: IOError: [Errno 22] invalid mode ('r') or filename: 'E:\Project\Selenium\Check\pronunciation_he_?\xe0\xc8\xe3\xe5\xc9\xed_\xe0\xc2\xe3\xe5\xcc\xee\xc8\xe4.mp3'

Thanks in advance!

EDIT CHANGING TO PYTHON 3 JUST SOLVED THE PROBLEM

0 Answers
Related