Skip to content Skip to sidebar Skip to footer

Python Windowserror: [error 123] The Filename, Directory Name, Or Volume Label Syntax Is Incorrect:

I am new to programming, this is actually my first work assignment with coding. my code below is throwing an error: WindowsError: [Error 123] The filename, directory name, or volu

Solution 1:

As it solved the problem, I put it as an answer.

Don't use single and double quotes, especially when you define a raw string with r in front of it.

The correct call is then

path = r"C:\Apps\CorVu\DATA\Reports\AlliD\Monthly Commission Reports\Output\pdcom1"

or

path = r'C:\Apps\CorVu\DATA\Reports\AlliD\Monthly Commission Reports\Output\pdcom1'

Solution 2:

I had a related issue working within Spyder, but the problem seems to be the relationship between the escape character ( "\") and the "\" in the path name Here's my illustration and solution (note single \ vs double \\ ):

path =   'C:\Users\myUserName\project\subfolder'path   # 'C:\\Users\\myUserName\\project\subfolder'os.listdir(path)              # gives windows errorpath =   'C:\\Users\\myUserName\\project\\subfolder'os.listdir(path)              # gives expected behavior

Solution 3:

I had a similar issue while working with Jupyter. I was trying to copy files from one directory to another using copy function of shutil. The problem was that I had forgotten to import the package.(Silly) But instead of python giving import error, it gave this error.

Solved by adding:

from shutil importcopy

Solution 4:

I had this problem with Django and it was because I had forgotten to start the virtual environment on the backend.

Solution 5:

I was facing same error with Django Rest Framework, It was nothing to do with UI, still was getting this error. I applied below solution, worked for me.

  • Restarted Machine.
  • Restarted Virtual Environment.

Post a Comment for "Python Windowserror: [error 123] The Filename, Directory Name, Or Volume Label Syntax Is Incorrect:"