smartpathlibrary

Library for working with paths to files and folders.

v1.0.1 Python 3.8+

Quick Install via pip
pip install smartpathlibrary

Description

smartpathlibrary v1.0.1


Library for working with paths to files and folders.


PyPI Downloads
GitHub release (latest by date)
PyPI - Downloads
GitHub top language
PyPI
GitHub
PyPI - Format


⚠️ Disclaimer

By using this software, you agree to the full disclaimer terms.

Summary: Software provided "AS IS" without warranty. You assume all risks.

Full legal disclaimer: See DISCLAIMER.md


Help:

pip install smartpathlibrary

from smartpathlibrary.tools import PathManager, Dir, File, get_root_path, PathNormalizer, Counter, Folder

# ========== WORK WITH PATHS ==========

# Check existence
file = File("document.txt")
print(file.exists())  # False or True

folder = Folder("/home/user/docs")
print(folder.exists())

# Path normalization for different OS
normalized = PathNormalizer.normalize("/home/user/my file.txt")
# On Linux: '/home/user/my\ file.txt'
# On Windows: '/home/user/my file.txt'


# ========== DIRECTORY TRAVERSAL ==========

dir_obj = Dir("/home/user/project")

# Get all files recursively
for file in dir_obj.get_files(recursive=True):
    print(file)

# Only files in root folder (no subfolders)
for file in dir_obj.get_files(recursive=False):
    print(file)

# Get all subdirectories
for subdir in dir_obj.get_dirs(recursive=True):
    print(subdir)

# Count
print(f"Files: {dir_obj.get_count_files(recursive=True)}")
print(f"Folders: {dir_obj.get_count_dirs(recursive=True)}")


# ========== PATH MANAGER ==========

pm = PathManager()

# Add single paths
pm.add_path("/home/user/project")
pm.add_path("/home/user/notes.txt")

# Add multiple paths
pm.add_paths([
    "/home/user/docs",
    "/home/user/readme.md"
])

# Get all files (recursive through all added folders)
all_files = list(pm.get_files(recursive=True))
print(f"Files found: {len(all_files)}")

# Get all subfolders
all_dirs = list(pm.get_dirs(recursive=True))

# Statistics
print(f"Total paths added: {pm.count}")
print(f"Total files (recursive): {pm.get_count_files()}")
print(f"Total folders: {pm.get_count_dirs()}")

# Remove paths
pm.remove_path("/home/user/notes.txt")
pm.remove_paths(["/home/user/docs"])

print(pm)  # Paths(2)


# ========== GET ABSOLUTE PATH ==========

abs_path = get_root_path("data/config.json")
print(abs_path)  # /full/path/to/script/folder/data/config.json


# ========== COUNT ITEMS IN ITERABLE ==========

counter = Counter()
items = [1, 2, 3, 4, 5]
print(counter.get_count(items))  # 5

License

BSD 3-Clause License

Copyright (©) 2026, Alexander Suvorov