Uh oh!
There was an error while loading. Please reload this page.
forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path~script.py
More file actions
Latest commit
70 lines (60 loc) · 1.83 KB
/
Copy path~script.py
File metadata and controls
70 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
This is a simple script that will scan through the current directory
and generate the corresponding DIRECTORY.md file, can also specify
files or folders to be ignored.
"""
importos
# Target URL (master)
URL="https://github.com/TheAlgorithms/Python/blob/master/"
deftree(d, ignores, ignores_ext):
return_markdown(d, ignores, ignores_ext, 0)
def_markdown(parent, ignores, ignores_ext, depth):
out=""
dirs, files= [], []
foriinos.listdir(parent):
full=os.path.join(parent, i)
name, ext=os.path.splitext(i)
ifiinignoresorextinignores_ext:
continue
ifos.path.isfile(full):
# generate list
pre=parent.replace("./", "").replace(" ", "%20")
# replace all spaces to safe URL
child=i.replace(" ", "%20")
files.append((pre, child, name))
else:
dirs.append(i)
# Sort files
files.sort(key=lambdae: e[2].lower())
forfinfiles:
pre, child, name=f
out+=" "*depth+"* ["+name.replace("_", " ") +"]("+URL+pre+"/"+child+")\n"
# Sort directories
dirs.sort()
foriindirs:
full=os.path.join(parent, i)
i=i.replace("_", " ").title()
ifdepth==0:
out+="## "+i+"\n"
else:
out+=" "*depth+"* "+i+"\n"
out+=_markdown(full, ignores, ignores_ext, depth+1)
returnout
# Specific files or folders with the given names will be ignored
ignores= [".vs",
".gitignore",
".git",
"~script.py",
"__init__.py",
]
# Files with given entensions will be ignored
ignores_ext= [
".md",
".ipynb",
".png",
".jpg",
".yml"
]
if__name__=="__main__":
withopen("DIRECTORY.md", "w+") asf:
f.write(tree(".", ignores, ignores_ext))