Reputation: 31
This is my code:
data_directory = Path('G:\Pneumonia\chest_xray\chest_xray')
train_directory = data_directory / 'train'
val_directory = data_directory / 'val'
test_directory = data_directory / 'test'
normal_cases_directory = train_directory / 'NORMAL'
pneumonia_cases_directory = train_directory / 'PNEUMONIA'
normal_cases = normal_cases_directory.glob('*.jpeg')
pneumonia_cases = pneumonia_cases_directory.glob('*.jpeg')
train_data = []
for images in normal_cases:
train_data.append((images, 0))
for images in pneumonia_cases:
train_data.append((images, 1))
train_data = pd.DataFrame(train_data, columns=['image', 'label'],index=None)
This is output: OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\u202aG:\Pneumonia\chest_xray\chest_xray\train\NORMAL'.
I noticed the \u202a symbol in the beginning but I don't know how to fix it.
Upvotes: 1
Views: 5905
Reputation: 189317
U+202A is an invisible character which affects the text's direction. You probably accidentally copy/pasted it from somewhere into your program source.
(It doesn't change the text's direction because it's already left-to-right. The character would make sense if the path name was written in a piece of e.g. Arabic or Hebrew text which otherwise runs right-to-left, and you wanted this Latin string to display left-to-right. Perhaps you copy/pasted it from somewhere like that?)
You can't see it but you can remove it simply by backspacing over it. Place the cursor on G:
and move left; you should notice that it takes two presses to move from the left side of the G to the left side of the opening single quote. Similarly, you can move back to the left of the G and type backspace to remove the invisible character there.
Upvotes: 0
Reputation: 718
Use raw strings to pass the path:
Path(r'G:\Pneumonia\chest_xray\chest_xray')
Upvotes: 2