Skip to content

Commit

Permalink
Merge pull request #622 from realpython/fix-issue-621-wrong-variable-…
Browse files Browse the repository at this point in the history
…name

Fix variable name and add `exist_ok=True`
  • Loading branch information
martin-martin authored Dec 18, 2024
2 parents 57344e7 + c16e853 commit 6301b57
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python-get-all-files-in-directory/create_large_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ class Item:

def create_item(item: Item, path_to: Path = Path.cwd()) -> None:

if not item.children and not item.junk_files:
path_to.joinpath(item.name).touch()
if not item.children and not item.num_junk_files:
path_to.joinpath(item.name).touch(exist_ok=True)
return

root = path_to.joinpath(item.name)
root.mkdir()
root.mkdir(exist_ok=True)

for child in item.children:
create_item(child, path_to=root)

for i in range(item.num_junk_files):
root.joinpath(f"{i}.txt").touch()
root.joinpath(f"{i}.txt").touch(exist_ok=True)


create_item(folder_structure)

0 comments on commit 6301b57

Please sign in to comment.