Library for working with paths to files and folders.
Project description
smartpathlibrary v1.0.0
Library for working with paths to files and folders.
⚠️ 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
Copyright (©) 2026, Alexander Suvorov
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartpathlibrary-1.0.0.tar.gz.
File metadata
- Download URL: smartpathlibrary-1.0.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0d4cab77d1c63cb1e06e84c1c4fc8094ac429a8d02be5b45e2e3883a2d49e1f
|
|
| MD5 |
4ec62eda076c50ad7b511375ac7771a8
|
|
| BLAKE2b-256 |
491531028f6219eeba8fbd147b6f4cd0d6a805c7c3bcf1ec53649ec04ff2ebfd
|
File details
Details for the file smartpathlibrary-1.0.0-py3-none-any.whl.
File metadata
- Download URL: smartpathlibrary-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2e3d48fca1c93a05f77d771c1c3e4388668f2dd1653dbd8ca11388bef91b4fb
|
|
| MD5 |
4b2f688e1a82036d3115c63b9db6fe93
|
|
| BLAKE2b-256 |
6d6f5f3e336b9cd4e2a4eb349cc91c11433c75ebe6cbbd7e43924ee12193b589
|