Reputation: 117
I'm using the following script
import os,sys
folder ='C:\Users\sohan.l\Desktop\New folder (3)\fwdfslabprograms'
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
But it throws the following error, how can I correct it? Error:
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:C:\\Users\\sohan.l\\Desktop\\New folder (3)\x0cwdfslabprograms/*.*
Upvotes: 1
Views: 111
Reputation: 76887
Use a raw string in your script
folder = r'C:\Users\sohan.l\Desktop\New folder (3)\fwdfslabprograms'
As it currently stands, the \f
is being read as a unicode character, which gets translated into a \x0c
character.
Since the folder name becomes wrong, the particular folder is obviously not found and a WindowsError
is thrown.
Upvotes: 3