Matt
Matt

Reputation: 179

Python Folder Name

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..

Upvotes: 0

Views: 307

Answers (1)

user2555451
user2555451

Reputation:

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'
>>>

Upvotes: 1

Related Questions