Skip to content

Load file creation and modification date to metadata with DirectoryLoader #13462

Answered by PrimozGodec
PrimozGodec asked this question in Q&A
Discussion options

You must be logged in to vote

Bot, thank you for response. Based on your solution, I created a bit different code:

class DateDirectoryLoader(DirectoryLoader):
    def load_file(
        self, item: Path, path: Path, docs: List[Document], pbar: Optional[Any]
    ) -> None:
        prev_len = len(docs)
        super().load_file(item, path, docs, pbar)
        if len(docs) > prev_len:
            # if any file was loaded by super().load_file == no error loading
            stat = os.stat(str(item))
            creation_date = datetime.fromtimestamp(stat.st_ctime).isoformat()
            modification_date = datetime.fromtimestamp(stat.st_mtime).isoformat()
            for doc in docs[prev_len:]:
                doc.metadata[

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Evil-Dr-Porkchop
Comment options

Answer selected by PrimozGodec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants