Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no path is passed to notebook, use this trick #1541

Open
johnjosephhorton opened this issue Feb 1, 2025 · 0 comments
Open

If no path is passed to notebook, use this trick #1541

johnjosephhorton opened this issue Feb 1, 2025 · 0 comments

Comments

@johnjosephhorton
Copy link
Contributor

import os
from pathlib import Path

def get_latest_notebook():
    """
    Returns the path to the most recently modified .ipynb file in the current directory.
    Returns None if no .ipynb files are found.
    """
    # Get all ipynb files in current directory
    notebook_files = list(Path('.').glob('*.ipynb'))
    
    if not notebook_files:
        return None
    
    # Get the most recent file based on modification time
    latest_notebook = max(notebook_files, key=lambda x: x.stat().st_mtime)
    
    return latest_notebook

# Example usage:
# latest_nb = get_latest_notebook()
# if latest_nb:
#     print(f"Most recent notebook: {latest_nb}")
# else:
#     print("No notebook files found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant