Application File Scanner
application-file-scanner is a small Python package designed to simplify the process of scanning directories for specific application-related files. It helps manage the complexities of file discovery within an application's execution environment. The current version is 0.6.4, with a release cadence that appears to be driven by feature additions and maintenance, previously being part of the PyMarkdown project.
Warnings
- breaking The core `ApplicationFileScanner` class was moved out of `PyMarkdown` to become a standalone package (`application-file-scanner`) starting with version 0.6.0. Direct imports from `pymarkdown.application_file_scanner` will no longer work.
- gotcha The `ApplicationFileScanner` is designed to be a lightweight tool. For complex or highly performant file system operations, consider specialized libraries or built-in Python modules like `os.walk` or `pathlib` for more granular control or performance optimizations.
Install
-
pip install application-file-scanner
Imports
- ApplicationFileScanner
from application_file_scanner import ApplicationFileScanner
Quickstart
import os
import shutil
from application_file_scanner import ApplicationFileScanner
# 1. Create a dummy directory and some files for demonstration
scan_directory = "temp_app_files_example"
os.makedirs(scan_directory, exist_ok=True)
with open(os.path.join(scan_directory, "main.py"), "w") as f:
f.write("print('Hello from app.py')")
with open(os.path.join(scan_directory, "config.ini"), "w") as f:
f.write("[Settings]\nAPP_NAME=MyApp")
with open(os.path.join(scan_directory, "data.txt"), "w") as f:
f.write("Some data...")
with open(os.path.join(scan_directory, "README.md"), "w") as f:
f.write("# README")
# 2. Instantiate the scanner
scanner = ApplicationFileScanner()
# 3. Define the directory to scan and desired file extensions
# The method name is inferred based on common patterns for file scanning libraries.
# Replace with actual directory and extensions for real use.
files_to_find = ['.py', '.ini']
# 4. Scan for files
# Assumes a method like 'get_application_files' or 'scan_files' based on library purpose.
# If a specific method is not found in documentation, this is a reasonable guess.
found_files = scanner.get_application_files(scan_path=scan_directory, file_extensions=files_to_find)
print(f"Scanning directory: {scan_directory}")
print(f"Looking for files with extensions: {files_to_find}")
if found_files:
print("\nFound application files:")
for file_path in found_files:
print(f"- {file_path}")
else:
print("\nNo application files found with specified extensions.")
# 5. Clean up the dummy directory
shutil.rmtree(scan_directory)