A simple folder management library
Project description
folder_manager
folder_manager
is a Python package designed to manage folders and files. It provides functionalities to create, list, count, and delete files and folders, making it a versatile tool for file management. The package is designed to be OS-independent, ensuring compatibility with both Windows and Unix-based systems.
Features
- Create Folder: Create a new folder at a specified path.
- List Files: List all files in a specified folder.
- Count Files: Count the number of files in a specified folder.
- Create File: Create a new file with optional content.
- Delete File: Delete a specified file.
- Delete Folder: Delete a specified folder and all its contents.
- Check Folder Exists: Check if a specified folder exists.
- Check File Exists: Check if a specified file exists.
Requirements
- Python 3.x
Installation
Install the package via PyPI using pip:
pip install folder_manager
Usage
Importing the Package
To use the folder_manager
package, import it into your Python script:
from folder_manager import Folder
Creating an Instance
To create an instance of the Folder
class, provide the path to the folder you want to manage.
folder = Folder("/path/to/folder")
Examples
-
Create a Folder:
folder = Folder("/path/to/folder") try: result = folder.create_folder() print(result) # Returns True if the folder was created successfully except FolderError as e: print(e)
-
List Files in a Folder:
folder = Folder("/path/to/folder") try: files = folder.list_files() print(files) # Returns a list of filenames in the folder except FolderError as e: print(e)
-
Count Files in a Folder:
folder = Folder("/path/to/folder") try: file_count = folder.count_files() print(f"Number of files: {file_count}") # Returns the number of files in the folder except FolderError as e: print(e)
-
Create a File:
folder = Folder("/path/to/folder") try: result = folder.create_file("file.txt", "Hello, World!") print(result) # Returns True if the file was created successfully except FolderError as e: print(e)
-
Delete a File:
folder = Folder("/path/to/folder") try: result = folder.delete_file("file.txt") print(result) # Returns True if the file was deleted successfully except FolderError as e: print(e)
-
Delete a Folder:
folder = Folder("/path/to/folder") try: result = folder.delete_folder() print(result) # Returns True if the folder was deleted successfully except FolderError as e: print(e)
-
Check if a Folder Exists:
folder = Folder("/path/to/folder") if folder.folder_exists(): print("Folder exists.") else: print("Folder does not exist.")
-
Check if a File Exists:
folder = Folder("/path/to/folder") if folder.file_exists("file.txt"): print("File exists.") else: print("File does not exist.")
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Author
Acknowledgments
- Thanks to the open-source community for providing the tools and inspiration for this project.
- Special thanks to all contributors and users of the package.
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
File details
Details for the file folder_manager-1.0.1.tar.gz
.
File metadata
- Download URL: folder_manager-1.0.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3581dfe41749fb58148394d1e6764f25e9506289a1bc99643fa128c6e3c0ae3e |
|
MD5 | 5c4f0ba2e78111647808a882df77fda7 |
|
BLAKE2b-256 | 53bd0449ab96e213b85d8c8fa4f392fe8273145612dbac96805826311b487af0 |
File details
Details for the file folder_manager-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: folder_manager-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d99703dd4616381f6851509b4b32f480c95a00d91edaba3a184f92566c988b |
|
MD5 | a0736b60f5a0aaeeb855332faedd56a5 |
|
BLAKE2b-256 | 126c7ba96a7e4e87bac4884888d7cbf3be385af6142268b7ae9e77625a98d10a |