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.0.tar.gz
.
File metadata
- Download URL: folder_manager-1.0.0.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 | 9f76ead8cb29d731ea68451d9468acc820c27ae13eb7d4014b4f3f83a66bb336 |
|
MD5 | b368bd956c9cf286828531c153d3c1b3 |
|
BLAKE2b-256 | b1d1605ac93136da068a066271b9f65393ea8d2789ab5b498103e769964dc978 |
File details
Details for the file folder_manager-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: folder_manager-1.0.0-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 | 8026b0f9fa7992e636651456b2af264c9aadfa468749894a8c9f678e7f272174 |
|
MD5 | 1604fbe12d025bf8cc05f8b2d5b5f32b |
|
BLAKE2b-256 | 6fe67faafb206b87f7996252e3c9c81622a70663784bc1360b26ce7f0c31a61c |