Skip to content

Commit 4cdd919

Browse files
committed
adding create large dir script
1 parent a9980bd commit 4cdd919

File tree

1,840 files changed

+83
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,840 files changed

+83
-5
lines changed

python-get-all-files-in-directory/README.md

Lines changed: 5 additions & 4 deletions

python-get-all-files-in-directory/bonus/testing_nested_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from listdir import recursive_listdir, recursive_listdir_gen
33
from make_files import make_recursive_nested_dir, recursive_rmdir
44
from scandir import recursive_scandir, recursive_scandir_gen
5-
from walk import get_list_from_walk, get_list_from_walk_pathlib
65
from timing import timeit_multiple
6+
from walk import get_list_from_walk, get_list_from_walk_pathlib
77

88
TIMEIT_TIMES = 100
99
LEVEL_OF_NESTING = 5
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
from pathlib import Path
5+
6+
7+
@dataclass
8+
class Item:
9+
name: str
10+
children: list[Item] = None
11+
junk_files: int = None
12+
13+
14+
folder_structure = Item(
15+
"large_dir",
16+
[
17+
Item(
18+
"documents",
19+
[
20+
Item(
21+
"notes",
22+
[
23+
Item(
24+
"temp",
25+
[Item("2", junk_files=300)],
26+
junk_files=300,
27+
),
28+
Item("0.txt"),
29+
Item("find_me.txt"),
30+
],
31+
),
32+
Item(
33+
"tools",
34+
[
35+
Item(
36+
"temporary_files",
37+
[
38+
Item("logs", junk_files=300),
39+
Item("temp", junk_files=300),
40+
],
41+
junk_files=25,
42+
),
43+
Item("33.txt"),
44+
Item("34.txt"),
45+
Item("36.txt"),
46+
Item("37.txt"),
47+
Item("real_python.txt"),
48+
],
49+
),
50+
],
51+
junk_files=5,
52+
),
53+
Item("temp", junk_files=300),
54+
Item("temporary_files", junk_files=300),
55+
],
56+
)
57+
58+
59+
def create_item(item: Item, path_to: Path = Path("")):
60+
61+
if item.children is None and item.junk_files is None:
62+
path_to.joinpath(item.name).touch()
63+
64+
if item.children or item.junk_files:
65+
root = path_to.joinpath(item.name)
66+
root.mkdir()
67+
68+
if item.children:
69+
for child in item.children:
70+
create_item(child, path_to=root)
71+
72+
if item.junk_files:
73+
for i in range(item.junk_files):
74+
root.joinpath(f"{i}.txt").touch()
75+
76+
77+
create_item(folder_structure)

python-get-all-files-in-directory/large_dir/documents/0.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/1.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/2.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/3.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/4.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/notes/0.txt

Whitespace-only changes.

python-get-all-files-in-directory/large_dir/documents/notes/find_me.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)