Added exclusion of hidden files and folders by default.

This commit is contained in:
The Wobbler 2025-04-10 11:27:29 +02:00
parent 7d5578e204
commit e1ac1ff083

8
omg.py
View file

@ -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):