close

[Solved] Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect:

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: Error Occurs?

Today I get the following error Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: in python.

How To Solve Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: Error ?

  1. How To Solve Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: Error ?

    To Solve Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: Error Don't use single and double quotes, especially when you define a raw string with r in front of it.

  2. Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect:

    To Solve Python Windows: [ 123] The filename, directory name, or volume label syntax is incorrect: Error Don't use single and double quotes, especially when you define a raw string with r in front of it.

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 error
path =   'C:\\Users\\myUserName\\project\\subfolder'
os.listdir(path)              # gives expected behavior

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read