Added exclusion of hidden files and folders by default.
This commit is contained in:
parent
7d5578e204
commit
e1ac1ff083
1 changed files with 7 additions and 1 deletions
8
omg.py
8
omg.py
|
@ -15,12 +15,13 @@ class OMG:
|
|||
(Like the Obsidian-plugin "Metadata Extractor" does.)
|
||||
"""
|
||||
|
||||
def __init__(self, path: str | os.PathLike) -> None:
|
||||
def __init__(self, path: str | os.PathLike, include_hidden: bool=False) -> None:
|
||||
"""
|
||||
Generates metadata for markdown files located at the given path.
|
||||
(Like the Obsidian-plugin "Metadata Extractor" does.)
|
||||
|
||||
:param PathLike path: The path where the markdown files are located
|
||||
:param bool include_hidden: If True, hidden folders and files (dotfiles) will also get searched.
|
||||
"""
|
||||
|
||||
self.path = path
|
||||
|
@ -28,6 +29,8 @@ class OMG:
|
|||
if not self.path[-1] == "/":
|
||||
self.path += "/"
|
||||
|
||||
self.include_hidden = include_hidden
|
||||
|
||||
self.md_files = self._parse_all_files(self.path)
|
||||
|
||||
def _parse_all_files(self, root: str | os.PathLike, path: str | os.PathLike = None) -> list:
|
||||
|
@ -40,6 +43,9 @@ class OMG:
|
|||
if filename in [".git", ".obsidian"]: # exclude .git and .obsidian
|
||||
continue
|
||||
|
||||
if filename[0] == "." and not self.include_hidden:
|
||||
continue
|
||||
|
||||
filepath = path + filename
|
||||
|
||||
if os.path.isdir(filepath):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue