1

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'
Mitra
  • 157
  • 2
  • 12

2 Answers2

2

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

now = datetime.datetime.utcnow().strftime("%b-%d_%H_%M_%S")
Shijith
  • 4,602
  • 2
  • 20
  • 34
2

: 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.

Bikramjeet Singh
  • 681
  • 1
  • 7
  • 22