It would greatly help debug this if you include examples of such filenames that give you trouble. However, I have a good idea on what is probably happening here.
This problems seem to appear on folders that start with r
or t
on their names. Also, as they are folders, on their full path name they are preceded by a \
character (for example "\thisFolder"
, or similar). This is true in the case of a Windows environment, as they use \
for separating paths contrary to *nix systems that use the regular slash /
.
Considering these things, seems that perhaps you are experiencing this as \r
and \t
are both special characters that mean Carriage Return and Tabulation, respectively. If this is the case many file openers will have trouble processing such file name.
Even more, I would not be surprised if you got the same errors on folders that begin with n
or other letters that when concatenated to a backslash give special characters (\n
is new line, \s
is a white space, etc.).
To overcome this seems that you will need to escape your backslash character before passing it as a filename. In python, an escaped backslash is "\\"
. In addition, you can also opt to pass a Raw string instead, by adding the r
prefix to your string, something like r"\a\raw\string"
. More information on escaping and raw string can be found on this question and answers.
I want to know if there are some specified rules on the filenames which should be avoided and otherwise would lead to such reading error in python,
As mentioned, you should avoid this with characters that have a special meaning with a backslash. I suggest you check here to see the characters Python accepts like this, so you can refrain from using such characters (or well use raw strings and forget about this problem).