Mitra
Mitra

Reputation: 157

OSError: The filename, directory name, or volume label syntax is incorrect

I am trying to create a new dictionary.

import os
import datetime


parent_dir = "E:\\"
directory = "cali"
now = datetime.datetime.utcnow().strftime("%b-%d_%H:%M:%S")

path = os.path.join(parent_dir, directory, now) 

os.makedirs(path) 

But I am getting this error:

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'E:\\cali\\Dec-25_07:53:44'

Upvotes: 1

Views: 3543

Answers (2)

Bikramjeet Singh
Bikramjeet Singh

Reputation: 686

: is one of the characters that are illegal for naming directories in Windows.

Therefore, you need to replace : in ("%b-%d_%H:%M:%S") with _ to resolve the error.

Upvotes: 2

Shijith
Shijith

Reputation: 4872

you cannot create a folder with : in name , instead replace

now = datetime.datetime.utcnow().strftime("%b-%d_%H_%M_%S")

Upvotes: 2

Related Questions