-1

How to create a directory inside the C:\ProgramData in Python?

I want to create Foo directory inside C:\ProgramData in Python

import os
from pathlib import Path, PurePath, PosixPath,PurePosixPath,PureWindowsPath,WindowsPath

path = WindowsPath("C:/PrgramData/Foo")

path.parent.mkdir(parents=True, exist_ok=True)
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101

1 Answers1

0

You can do this simply with the makedirs() function from the os module as follows:

import os

os.makedirs(r'C:\ProgramData\Foo', exist_ok=True)
DarkKnight
  • 19,739
  • 3
  • 6
  • 22