I have a directory in my computer which is having a numeral as the folder name.. For Example, the directory that exist is
C:\\3_Software
I am trying to provide the top level directory path.. I want to look into folders, subfolders and files from C:\\3_Software, open the file and search for a string. If the specific string exist, then print the file name and the string. So I used the os.walk to iterate over the folders, subfolders and files. Now when it is fetching the directory name, since it has a numeral in the folder name, it is automatically converting to a different format and unable to fetch the file from there.
When i tried to define the 'C:\\3_Software' as root and read back the same variable, it is giving me as 'C:\\x03_Software'....
And, is there any means of concatenating the root and file path... using the os.walk method..
Escape the backslash:
'C:\\3_Software'
or make it a raw string:
r'C:\3_Software'
As your code currently stands, you are trying to use character "\\3":
>>> '\3'
'\x03'
>>>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.