Created
August 2, 2022 02:53
-
-
Save michaeltoohig/fc4c97cba43bd2f208d81eb1a18d07ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
import random | |
from pathlib import Path | |
def make_file(path: Path): | |
file_name = str(uuid.uuid4().hex) | |
new_path = path / file_name | |
new_path.touch() | |
if random.random() > 0.95: | |
with new_path.open("w") as f: | |
f.write("FLAG") | |
return new_path | |
def make_directory(path: Path): | |
directory_name = str(uuid.uuid4().hex) | |
new_path = path / directory_name | |
new_path.mkdir() | |
return new_path | |
def recursive_subdirectory(path: Path, depth: int): | |
# create random files in the current directory | |
files = random.randint(1, 10) | |
for _ in range(files): | |
make_file(path) | |
# create deeper directories | |
if depth > 10: | |
return | |
elif depth < 4: | |
dirs = random.randint(2, 5) | |
for _ in range(dirs): | |
new_directory = make_directory(path) | |
new_depth = depth + 1 | |
recursive_subdirectory(path=new_directory, depth=new_depth) | |
else: | |
if random.random() > 0.25: | |
new_directory = make_directory(path) | |
new_depth = depth + 1 | |
recursive_subdirectory(path=new_directory, depth=new_depth) | |
starting_point = Path("./directories") | |
starting_point.mkdir(exist_ok=True) | |
recursive_subdirectory(path=starting_point, depth=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment