Skip to main content

A flexible utility for creating project snapshots and searching for files.

Project description

Dirshot: A Flexible Project Snapshot and Search Tool

Dirshot is a Python utility that creates snapshots of a project's directory structure and file contents. It can operate in two modes: filtering files based on their type and path, or searching for files based on keywords in their name or content.

The script generates a single output file containing a directory tree and the concatenated text of the selected files. This is useful for quickly gathering project context for code analysis, sharing with collaborators, or providing to a Large Language Model (LLM).

Key Features

  • Two Operating Modes:
    • Filter Mode: Create a snapshot of your project by filtering files based on extensions, filenames, and directory paths.
    • Search Mode: Search for files containing specific keywords in their name, path, or content.
  • Customizable Filtering:
    • Use language presets for popular languages (Python, JavaScript, Java, etc.).
    • Use ignore presets to exclude common files and directories (e.g., .git, node_modules, __pycache__).
    • Define custom file types, and whitelist/blacklist substrings in filenames and paths.
  • Flexible Tree Generation:
    • Display a directory tree in various styles (Unicode, ASCII, Compact).
    • Show statistics for included/matched files and directories in the tree.
  • Content Collation:
    • Concatenates the content of all selected files into a single output file.
    • Optionally display an approximated token/character count.
  • Snapshot Deconstruction:
    • A utility function to parse a generated snapshot file and extract the directory tree and file paths.

Installation

You can install Dirshot from PyPI:

pip install dirshot

Usage

Here are some examples of how to use Dirshot in your own Python scripts.

Example 1: Creating a Snapshot with Presets (Filter Mode)

This example creates a snapshot of a Python project, ignoring common virtual environment and build directories.

from dirshot import filter_project, LanguagePreset, IgnorePreset

filter_project(
    root_dir_param=".",
    output_file_name="project_snapshot.txt",
    language_presets=[LanguagePreset.PYTHON],
    ignore_presets=[
        IgnorePreset.PYTHON_ENV,
        IgnorePreset.NODE_MODULES,
        IgnorePreset.BUILD_ARTIFACTS,
    ],
    show_token_count=True,
)

Example 2: Searching for Keywords in a Project (Search Mode)

This example searches for the keywords "API" or "Controller" within .java and .js files.

from dirshot import find_in_project

find_in_project(
    root_dir_param="example_project",
    output_file_name="search_results.txt",
    search_keywords=["API", "Controller"],
    file_extensions_to_check=[".java", ".js"],
    ignore_dirs_in_path=["node_modules", "build"],
    search_file_contents=True,
    show_tree_stats=True,
)

Deconstructing a Snapshot

You can also parse a previously generated snapshot file to extract the directory structure and the list of included files.

from dirshot import deconstruct_snapshot

snapshot_data = deconstruct_snapshot("project_snapshot.txt")
print("Directory Tree:")
for line in snapshot_data["tree_lines"]:
    print(line)

print("\nIncluded Files:")
for file_path in snapshot_data["file_paths"]:
    print(file_path)

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on the project's GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dirshot-0.1.3.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dirshot-0.1.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file dirshot-0.1.3.tar.gz.

File metadata

  • Download URL: dirshot-0.1.3.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for dirshot-0.1.3.tar.gz
Algorithm Hash digest
SHA256 962944fc8fb606a61b5bd7b0fc41014c74ca368c45233fa55f55c96be84f5887
MD5 0a43b907b0941ebda4f0fe639789476c
BLAKE2b-256 cb25982eb5b313af231d75374c9b315b6bc1c304c2327a8670c061eac2554f42

See more details on using hashes here.

File details

Details for the file dirshot-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: dirshot-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for dirshot-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d598bd1cd26c932d1a686f37a0c518583d576acc4835075f13c742c05e42d18c
MD5 4de55b835addbdf6b6eca6cd5ffe67ab
BLAKE2b-256 23761e92c19c97dd52f5bc5458d1d1f9baab1567c4478df14d564fa6c7c4c311

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page