Lädt...


🔧 Path.mkdir(parents, exist_ok) in Python


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

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

🔧 Path.mkdir(parents, exist_ok) in Python


📈 87.79 Punkte
🔧 Programmierung

🕵️ CVE-2023-40499 | LG Simple Editor mkdir path traversal (ZDI-23-1205)


📈 29.54 Punkte
🕵️ Sicherheitslücken

🐧 Python OS Mkdir


📈 28.99 Punkte
🐧 Linux Tipps

🐧 Is mkdir ( or other commands ) system command or system call?


📈 23.7 Punkte
🐧 Linux Tipps

🕵️ GNU Guile up to 2.0.12 mkdir mode privilege escalation


📈 23.7 Punkte
🕵️ Sicherheitslücken

🕵️ Unix mkdir race condition privilege escalation


📈 23.7 Punkte
🕵️ Sicherheitslücken

🕵️ IBM AIX 5.3.0 mkdir privilege escalation


📈 23.7 Punkte
🕵️ Sicherheitslücken

🕵️ YaPiG 0.92b/0.93u/0.94u mkdir upload.php directory traversal


📈 23.7 Punkte
🕵️ Sicherheitslücken

💾 Linux/x86_64 mkdir Shellcode


📈 23.7 Punkte
💾 IT Security Tools

⚠️ [shellcode] Linux/x86 - mkdir(hacked) + exit() Shellcode (36 bytes)


📈 23.7 Punkte
⚠️ PoC

💾 Linux/x86_64 mkdir() Shellcode


📈 23.7 Punkte
💾 IT Security Tools

⚠️ [shellcode] Linux/x86_64 - mkdir() 'evil' Shellcode (30 bytes)


📈 23.7 Punkte
⚠️ PoC

⚠️ [shellcode] - Linux/x86-64 - mkdir Shellcode (25 bytes)


📈 23.7 Punkte
⚠️ PoC

🕵️ GNU Guile bis 2.0.12 mkdir mode erweiterte Rechte


📈 23.7 Punkte
🕵️ Sicherheitslücken

⚠️ [shellcode] - Linux/x86-64 - mkdir Shellcode (25 bytes)


📈 23.7 Punkte
⚠️ PoC

🕵️ CVE-2023-48648 | Concrete CMS up to 8.5.12/9.2.1 File Creation Mkdir permission


📈 23.7 Punkte
🕵️ Sicherheitslücken

🕵️ GNU Guile bis 2.0.12 mkdir mode erweiterte Rechte


📈 23.7 Punkte
🕵️ Sicherheitslücken

📰 Duo aus find und mkdir überraschend Turing-vollständig


📈 23.7 Punkte
🤖 Android Tipps

🐧 Make Directory using mkdir Command in Linux


📈 23.7 Punkte
🐧 Linux Tipps

🐧 Mkdir


📈 23.7 Punkte
🐧 Linux Tipps

📰 Pufferüberlauf in python-crcmod, python-cryptography und python-cryptography-vectors (SUSE)


📈 15.85 Punkte
📰 IT Security Nachrichten

🔧 Introducing More Python for Beginners | More Python for Beginners [1 of 20] | More Python for Beginners


📈 15.85 Punkte
🔧 Programmierung

🔧 What Makes Python Python? (aka Everything About Python’s Grammar)


📈 15.85 Punkte
🔧 Programmierung

🔧 Python for Beginners [1 of 44] Programming with Python | Python for Beginners


📈 15.85 Punkte
🔧 Programmierung

📰 Any books similar to Black Hat Python, or Violent Python that use Python v3?


📈 15.85 Punkte
📰 IT Security Nachrichten

matomo