Skip to main content

A tool to map directory contents and save output as TXT or JSON.

Project description

Documentation for mapContentTool.py

Overview

mapContentTool.py is a command-line tool for mapping the structure of a directory, selecting files and folders interactively, and exporting the directory structure with selected file contents. The output can be saved as a .txt (default) or .json file. Additionally, the tool can be installed as a Python library to provide the map-content command for direct usage.


Features

  • Interactive Selection:
    • Navigate directory structures.
    • Select or deselect files and folders interactively.
  • Recursive Handling:
    • Selecting a folder includes all its files and subfolders.
    • Deselecting a folder removes all its files and subfolders from the selection.
  • File Content Embedding:
    • Embeds the content of selected files directly into the output structure.
  • Output Options:
    • Default: .txt format.
    • Optional: .json format with a detailed structure.
  • Exclusion Capabilities:
    • Exclude specific directories (e.g., node_modules, .git).
  • Convenient Command:
    • Install as a Python library to use the map-content command directly.
  • Comprehensive Logging:
    • Logs all actions and errors for debugging and tracking.

Installation

You can install mapContentTool.py as a Python package via pip:

pip install map-content-tool

Usage

Command-Line Options

python mapContentTool.py [directory] [options]

Or, after installation, use the standalone command:

map-content [directory] [options]

Options

Option Description Default
[directory] Root directory to scan. If not provided, the current directory is used. Current directory
-o, --output Specify the output file. Supports .txt (default) and .json. output.txt
-e, --exclude Space-separated list of directories to exclude from scanning. node_modules, .git

Examples

Using Python Script

  1. Basic Usage:

    python mapContentTool.py
    
    • Scans the current directory.
    • Outputs the structure to output.txt.
  2. Specify an Output File:

    python mapContentTool.py -o my_directory.json
    
    • Outputs the directory structure to my_directory.json.
  3. Exclude Specific Directories:

    python mapContentTool.py -e dist build
    
    • Excludes the dist and build directories from the scan.
  4. Scan a Custom Directory:

    python mapContentTool.py /path/to/directory
    
    • Scans the /path/to/directory and outputs the structure to output.txt.

Using the map-content Command

  1. Basic Usage:

    map-content
    
    • Scans the current directory.
    • Outputs the structure to output.txt.
  2. Custom Directory:

    map-content /path/to/directory
    
  3. Exclude Specific Directories:

    map-content -e dist build
    
  4. Output as JSON:

    map-content -o output.json
    

Output Format

Default .txt Format

  • The .txt format retains the JSON-like structure for readability.

Optional .json Format

  • Example:
{
  "name": "root_folder",
  "path": "/path/to/root_folder",
  "type": "directory",
  "items": [
    {
      "name": "subfolder1",
      "path": "/path/to/root_folder/subfolder1",
      "type": "directory",
      "items": [
        {
          "name": "file1.txt",
          "path": "/path/to/root_folder/subfolder1/file1.txt",
          "type": "file",
          "contents": "This is the content of file1.txt."
        }
      ]
    }
  ]
}

Interactive UI

Navigation

  • Arrow keys: Move through the directory tree.
  • Space: Select or deselect files and folders.
  • Enter: Confirm selection and generate output.
  • Q: Quit without saving.

Logs

  • Logs are written to file_selector.log.
  • Tracks:
    • Errors
    • Directory scanning progress
    • File content embedding
    • User interactions

Error Handling

  • Handles missing directories and permission errors gracefully.
  • If any uncaught exception occurs, it logs the error and exits with a message to check the logs.

Dependencies

  • Python 3.x
  • Modules:
    • os
    • json
    • urwid
    • logging
    • sys
    • argparse
    • setuptools

Changelog

Latest Updates

  • Made .txt the default output format.
  • Added .json as an optional output format.
  • Restored the functionality of showing selected files inside a folder.
  • Improved folder selection and deselection logic to include all nested items.
  • Updated logging and documentation.
  • Enabled the use of the map-content standalone command via setuptools.

Known Issues

  • None at the moment.

For feature requests or bug reports, please contact the developer or create an issue in the 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

map_content_tool-1.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

map_content_tool-1.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file map_content_tool-1.1.0.tar.gz.

File metadata

  • Download URL: map_content_tool-1.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for map_content_tool-1.1.0.tar.gz
Algorithm Hash digest
SHA256 aa5b405e441eaa2eec3edb66aa4fb2f00d0b62457b8a604d659399086231c744
MD5 7b8c9299e3839fc2f1aa16315cce22dc
BLAKE2b-256 d349cb7c1f1416bd5228bd9f85f5bcfc9d34987caa85a0df41aa85d3de08d883

See more details on using hashes here.

File details

Details for the file map_content_tool-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for map_content_tool-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dca3fd2fbdb17b6ce978c78dd2dfcb9818e67134e30a9500bf3a4615a0ddf149
MD5 e986de02b5a1a5cccd6fa5cd84e0b603
BLAKE2b-256 ff6ec15ecd65f75c9d8c76c023bbc4292abafff83090953c354ab8e2fed72e53

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