Name | PathNavigator JSON |
Version |
0.4.1
JSON |
| download |
home_page | None |
Summary | A Python library for efficient directory and file navigation |
upload_time | 2024-11-26 13:24:30 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License Copyright (c) 2024 Chung-Yi Lin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![PyPI](https://img.shields.io/pypi/v/pathnavigator)](https://pypi.org/project/pathnavigator/)
[![Docs](https://github.com/philip928lin/PathNavigator/actions/workflows/docs.yml/badge.svg)](https://philip928lin.github.io/PathNavigator/)
![Test](https://github.com/philip928lin/PathNavigator/actions/workflows/test.yml/badge.svg)
# 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`](https://docs.python.org/3/library/pathlib.html), which adapt automatically across platforms.
## Installation
```bash
pip install PathNavigator
```
Install the latest version from GitHub repo:
```bash
pip install git+https://github.com/philip928lin/PathNavigator.git
```
## Getting Started
```python
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
```python
# 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
```python
# Update the folder structure to fit the latest structure in the file system.
pn.reload()
```
### System Path Management
```python
# Add the directory to folder1 to sys path.
pn.forlder1.add_to_sys_path()
```
### Changing Directories
```python
# Change the working directory to folder2.
pn.forlder1.forlder2.chdir()
```
### Shortcuts Management
#### Add shortcuts
```python
# 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
```python
# Retrieve the path of "f1" shortcut
pn.sc.f1
pn.sc.get("f1")
pn.sc.get_str("f1")
```
#### Other shortcut operations
```python
# 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](https://github.com/philip928lin/PathNavigator/actions/workflows/docs.yml/badge.svg)](https://philip928lin.github.io/PathNavigator/)
Raw data
{
"_id": null,
"home_page": null,
"name": "PathNavigator",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Chung-Yi Lin <philip928lin@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/26/f5/ad0d21edcb65c880ab946705558a3ea6c14e87c6e3d307445d02ab5e94cb/pathnavigator-0.4.1.tar.gz",
"platform": null,
"description": "[![PyPI](https://img.shields.io/pypi/v/pathnavigator)](https://pypi.org/project/pathnavigator/)\n[![Docs](https://github.com/philip928lin/PathNavigator/actions/workflows/docs.yml/badge.svg)](https://philip928lin.github.io/PathNavigator/)\n![Test](https://github.com/philip928lin/PathNavigator/actions/workflows/test.yml/badge.svg)\n\n# PathNavigator\n\n`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`](https://docs.python.org/3/library/pathlib.html), which adapt automatically across platforms. \n\n\n## Installation\n\n```bash\npip install PathNavigator\n```\n\nInstall the latest version from GitHub repo:\n```bash\npip install git+https://github.com/philip928lin/PathNavigator.git\n```\n\n## Getting Started\n\n```python\nfrom pathnavigator import PathNavigator\n\npn = PathNavigator(\"root_dir\")\n\n# Retrieve the full path of folder1\npn.folder1.get() # returns the full path to folder1 as a Path object\npn.folder1.get_str() # returns the full path to folder1 as a string. Same as str(pn.folder1.get()).\npn.folder1.get(\"file.txt\") # returns the full path to file.txt as a Path object\npn.folder1.get_str(\"file.txt\") # returns the full path to file.txt as a string. Same as str(pn.folder1.get(\"file.txt\")).\n\n# Set shortcuts\npn.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)\npn.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\"))\n\n# List directory contents\npn.folder1.ls() # prints the contents (subfolders and files) of folder1\n\n# Print the nested folder structure\npn.tree()\n\n# Directory management\npn.mkdir('folder1', 'folder2') # create a subfolder structure\npn.remove('folder1') # remove a file or subfolder and delete it\n```\n\n## Features\n\n### Directory and File Operations\n```python\n# Returns the full path to folder1.\npn.folder1.get() # Return a Path object\npn.folder1.get_str() # Return a string\n\n# Return the full path to file1.\npn.folder1.get(\"file.csv\") # Return a Path object\npn.folder1.get_str(\"file.csv\") # Return a string\n\n# Rrints the contents (subfolders and files) of folder1.\npn.folder1.ls() \n\n# Make the nested directories.\n# Directory root/folder1/subfolder1/subsubfolder2 will be created\npn.folder1.mkdir(\"subfolder1\", \"subsubfolder2\")\n\n# Removes a file or a folder and deletes it from the filesystem including all nested items.\n# The following code will delete the directory of root/folder1/folder2\npn.folder1.remove('folder2') \n\n# Combine folder1 directory with \"subfolder1/fileX.txt\" and return it.\npn.folder1.join(\"subfolder1\", \"fileX.txt\") \n\n# Or, you can utilize Path feature to join the paths.\npn.folder1.get() / \"subfolder1/fileX.txt\"\n```\n\n### Reloading folder structure\n```python\n# Update the folder structure to fit the latest structure in the file system.\npn.reload() \n```\n\n### System Path Management\n```python\n# Add the directory to folder1 to sys path.\npn.forlder1.add_to_sys_path() \n```\n\n### Changing Directories\n```python\n# Change the working directory to folder2.\npn.forlder1.forlder2.chdir() \n```\n\n### Shortcuts Management\n#### Add shortcuts\n```python\n# Set a shortcut named \"f1\" to folder1.\n# Can be accessed by pn.sc.f1 or pn.sc.get(\"f1\") or pn.sc.get_str(\"f1\").\npn.folder1.set_sc(\"f1\")\n\n# Set a shortcut named \"x\" to the file \"x.txt\" in folder1.\n# Can be accessed by pn.sc.x or pn.sc.get(\"x\") or pn.sc.get_str(\"x\").\npn.folder1.set_sc(\"x\", \"x.txt\")\n\n# Directly add shortcuts in pn.sc\npn.sc.add('f', pn.folder1.get(\"file\")) \npn.sc.add('f', r\"new/path\") \n```\n\n#### Retrieve shortcuts\n```python\n# Retrieve the path of \"f1\" shortcut\npn.sc.f1\npn.sc.get(\"f1\") \npn.sc.get_str(\"f1\") \n```\n\n#### Other shortcut operations\n```python\n# Print all shortcuts\npn.sc.ls() \n\n# Remove a shortcut\npn.sc.remove('f') \n\n# Return a dictionary of shortcuts\npn.sc.to_dict() \n\n# Output of shortcuts json file\npn.sc.to_json(filename) \n\n# Load shortcuts from a dictionary\npn.sc.load_dict() \n\n# Load shortcuts from a json file\npn.sc.load_json(filename) \n```\n\n## API reference\n[![Docs](https://github.com/philip928lin/PathNavigator/actions/workflows/docs.yml/badge.svg)](https://philip928lin.github.io/PathNavigator/)",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Chung-Yi Lin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A Python library for efficient directory and file navigation",
"version": "0.4.1",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f6a1fc876ff71f6201e82767b42010e2b31213af855e2fd72a46eb6c25b8d622",
"md5": "cfa4e38e160d4ec9523b8e17833b3503",
"sha256": "3e97005652cd3c4ed8154f39f9963848cca5f0d63dbb05b725b948534b89a1a3"
},
"downloads": -1,
"filename": "pathnavigator-0.4.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "cfa4e38e160d4ec9523b8e17833b3503",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 12629,
"upload_time": "2024-11-26T13:24:29",
"upload_time_iso_8601": "2024-11-26T13:24:29.259868Z",
"url": "https://files.pythonhosted.org/packages/f6/a1/fc876ff71f6201e82767b42010e2b31213af855e2fd72a46eb6c25b8d622/pathnavigator-0.4.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "26f5ad0d21edcb65c880ab946705558a3ea6c14e87c6e3d307445d02ab5e94cb",
"md5": "783424463a5999f5fbcf485375b06bfb",
"sha256": "cd19575d6d1685e43c1e29cfe10cb2500b00860cd6fd9979030426124ea982a6"
},
"downloads": -1,
"filename": "pathnavigator-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "783424463a5999f5fbcf485375b06bfb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15339,
"upload_time": "2024-11-26T13:24:30",
"upload_time_iso_8601": "2024-11-26T13:24:30.059760Z",
"url": "https://files.pythonhosted.org/packages/26/f5/ad0d21edcb65c880ab946705558a3ea6c14e87c6e3d307445d02ab5e94cb/pathnavigator-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 13:24:30",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pathnavigator"
}