Skip to main content

A Python library for efficient directory and file navigation

Project description

PyPI Docs Test

PathNavigator

PathNavigator is a Python package designed to navigate directories and files efficiently. It provides tools to interact with the filesystem, allowing users to create, delete, and navigate folders and files, while also maintaining an internal representation of the directory structure. Customized shortcuts can be added. The paths are stored as Path objects from pathlib, which adapt automatically across platforms.

Installation

pip install PathNavigator

Install the latest version from GitHub repo:

pip install git+https://github.com/philip928lin/PathNavigator.git

Getting Started

from pathnavigator import PathNavigator

pn = PathNavigator("root_dir")

# Retrieve the full path of folder1
pn.folder1.get()        # returns the full path to folder1 as a Path object
pn.folder1.get_str()    # returns the full path to folder1 as a string. Same as str(pn.folder1.get()).
pn.folder1.get("file.txt")        # returns the full path to file.txt as a Path object
pn.folder1.get_str("file.txt")    # returns the full path to file.txt as a string. Same as str(pn.folder1.get("file.txt")).

# Set shortcuts
pn.folder1.set_sc('my_folder')  # set the shortcut for folder1 (accessed by pn.sc.my_folder or pn.sc.get("my_folder") or pn.sc.get_str)
pn.folder1.set_sc('my_file', 'file.txt')  # set the shortcut for file.txt (accessed by pn.sc.my_file or pn.sc.get("my_file") or pn.sc.get_str("my_file"))

# List directory contents
pn.folder1.ls()         # prints the contents (subfolders and files) of folder1

# Print the nested folder structure
pn.tree()

# Directory management
pn.mkdir('folder1', 'folder2')  # create a subfolder structure
pn.remove('folder1')    # remove a file or subfolder and delete it

Features

Directory and File Operations

# Returns the full path to folder1.
pn.folder1.get()        # Return a Path object
pn.folder1.get_str()    # Return a string

# Return the full path to file1.
pn.folder1.get("file.csv")      # Return a Path object
pn.folder1.get_str("file.csv")  # Return a string

# Rrints the contents (subfolders and files) of folder1.
pn.folder1.ls()         

# Make the nested directories.
# Directory root/folder1/subfolder1/subsubfolder2 will be created
pn.folder1.mkdir("subfolder1", "subsubfolder2")

# Removes a file or a folder and deletes it from the filesystem including all nested items.
# The following code will delete the directory of root/folder1/folder2
pn.folder1.remove('folder2')    

# Combine folder1 directory with "subfolder1/fileX.txt" and return it.
pn.folder1.join("subfolder1", "fileX.txt") 

# Or, you can utilize Path feature to join the paths.
pn.folder1.get() / "subfolder1/fileX.txt"

Reloading folder structure

# Update the folder structure to fit the latest structure in the file system.
pn.reload() 

System Path Management

# Add the directory to folder1 to sys path.
pn.forlder1.add_to_sys_path()   

Changing Directories

# Change the working directory to folder2.
pn.forlder1.forlder2.chdir()    

Shortcuts Management

Add shortcuts

# Set a shortcut named "f1" to folder1.
# Can be accessed by pn.sc.f1 or pn.sc.get("f1") or pn.sc.get_str("f1").
pn.folder1.set_sc("f1")

# Set a shortcut named "x" to the file "x.txt" in folder1.
# Can be accessed by pn.sc.x or pn.sc.get("x") or pn.sc.get_str("x").
pn.folder1.set_sc("x", "x.txt")

# Directly add shortcuts in pn.sc
pn.sc.add('f', pn.folder1.get("file"))  
pn.sc.add('f', r"new/path")  

Retrieve shortcuts

# Retrieve the path of "f1" shortcut
pn.sc.f1
pn.sc.get("f1")  
pn.sc.get_str("f1") 

Other shortcut operations

# Print all shortcuts
pn.sc.ls()       

# Remove a shortcut
pn.sc.remove('f')   

# Return a dictionary of shortcuts
pn.sc.to_dict()  

# Output of shortcuts json file
pn.sc.to_json(filename)  

# Load shortcuts from a dictionary
pn.sc.load_dict()  

# Load shortcuts from a json file
pn.sc.load_json(filename)  

API reference

Docs

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

pathnavigator-0.4.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

pathnavigator-0.4.1-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pathnavigator-0.4.1.tar.gz.

File metadata

  • Download URL: pathnavigator-0.4.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pathnavigator-0.4.1.tar.gz
Algorithm Hash digest
SHA256 cd19575d6d1685e43c1e29cfe10cb2500b00860cd6fd9979030426124ea982a6
MD5 783424463a5999f5fbcf485375b06bfb
BLAKE2b-256 26f5ad0d21edcb65c880ab946705558a3ea6c14e87c6e3d307445d02ab5e94cb

See more details on using hashes here.

File details

Details for the file pathnavigator-0.4.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pathnavigator-0.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3e97005652cd3c4ed8154f39f9963848cca5f0d63dbb05b725b948534b89a1a3
MD5 cfa4e38e160d4ec9523b8e17833b3503
BLAKE2b-256 f6a1fc876ff71f6201e82767b42010e2b31213af855e2fd72a46eb6c25b8d622

See more details on using hashes here.

Supported by

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