Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••••••••
Sicherheitslücken (CVE)CVE-2025-65823 | Meatmeet App on Android hard-coded credentials(29.09.2026 um 03:42 Uhr)
••••••••••
Sicherheitslücken (CVE)CVE-2025-65823 | Meatmeet App on Android hard-coded credentials(29.09.2026 um 03:42 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Path.mkdir(parents, exist_ok) in Python

Buy Me a Coffee☕ Path.mkdir() can create zero or more directories as shown below: *Memos: There is the 1st argument for Path() (Required-Type:str, bytes or os.PathLike). *Its argument name doesn't exist. The 1st argument is mode for m…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Buy Me a Coffee☕



Path.mkdir() can create zero or more directories as shown below:



*Memos:




  • There is the 1st argument for Path() (Required-Type:str, bytes or os.PathLike). *Its argument name doesn't exist.

  • The 1st argument is mode for mkdir() (Optional-Default:0o777-Type:int).

  • The 2nd argument is parents for mkdir() (Optional-Default:False-Type:bool):
    *Memos:


    • If it's False, the path with a target directory and one or more non-existent parent directories cannot be created, getting FileNotFoundError.

    • If it's True, the path with a target directory and one or more non-existent parent directories can be created, not getting FileNotFoundError.

    • Basically, True is set to it.






  • The 3rd argument is exist_ok for mkdir() (Optional-Default:False-Type:bool):
    *Memos:


    • If it's False, FileExistsError is raised for an existent path.

    • If it's True, FileExistsError isn't raised for an existent path.

    • Basically, True is set to it.









#     Parent directories
# ↓↓↓↓ ↓↓↓↓↓↓
p = Path('dir3/dir3_1/dir3_1_1')
# ↑↑↑↑↑↑↑↑
# A target directory









1. Creating dir1 is successful:






from pathlib import Path

p = Path('dir1')

p.mkdir()
# Or
# p.mkdir(mode=0o777, parents=False, exist_ok=False)

# my_project
# └-dir1 <- Here









2. Recreateing dir1 is failed and gets FileExistsError:






from pathlib import Path

p = Path('dir1')

p.mkdir()
# FileExistsError: [Errno 17] File exists: 'dir1'

# my_project
# └-dir1









3. Recreating dir1 with exist_ok=True is failed but doesn't get FileExistsError:






from pathlib import Path

p = Path('dir1')

p.mkdir(exist_ok=True)

# my_project
# └-dir1









4. Creating dir1_1 in dir1 is successful:






from pathlib import Path

p = Path('dir1/dir1_1')

p.mkdir()

# my_project
# └-dir1
# └-dir1_1 <- Here









5. Creating dir2/dir2_1 is failed and gets FileNotFoundError:






from pathlib import Path

p = Path('dir2/dir2_1')

p.mkdir()
# FileNotFoundError: [Errno 2] No such file or directory: 'dir2/dir2_1'

# my_project
# └-dir1
# └-dir1_1









6. Creating dir2/dir2_1 with parents=True is successful:






from pathlib import Path

p = Path('dir2/dir2_1')

p.mkdir(parents=True)

# my_project
# |-dir1
# | └-dir1_1
# └-dir2 <- Here
# └-dir2_1 <- Here









7. Creating dir3/dir3_1/dir3_1_1 with parents=True and exist_ok=True is successful:






from pathlib import Path

p = Path('dir3/dir3_1/dir3_1_1')

p.mkdir(parents=True, exist_ok=True)

# my_project
# |-dir1
# | └-dir1_1
# |-dir2
# | └-dir2_1
# └-dir3 <- Here
# └-dir3_1 <- Here
# └-dir3_1_1 <- Here









8. Recreating dir3/dir3_1/dir3_1_1 with parents=True and exist_ok=True is failed but doesn't get FileExistsError:






from pathlib import Path

p = Path('dir3/dir3_1/dir3_1_1')

p.mkdir(parents=True, exist_ok=True)

# my_project
# |-dir1
# | └-dir1_1
# |-dir2
# | └-dir2_1
# └-dir3
# └-dir3_1
# └-dir3_1_1


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Path.mkdir(parents, exist_ok) in Python

Thematisch verwandte Begriffe: Pathmkdirparents, existok, Python · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-102265 | PyJWT is a Python implementation of JSON Web Token standards. From 2.13…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag