A package for file management
Project description
File Management Package
file-management-package
is a Python package designed to simplify file management tasks. It provides a convenient set of tools to create, read, write, delete, and manage files in a system, while handling common errors and ensuring robust functionality.
Features
- File Writing: Write to a file, either appending or writing a single line.
- File Reading: Read a file either line by line or as a whole.
- File Existence Check: Check if a file exists.
- File Creation: Automatically create a file if it doesn't exist.
- File Deletion: Delete a file from the system.
- File Content Modification: Remove specific content from a file.
- File Opening: Open files using the default application for the file type.
Installation
To install the package, use the following command:
pip install file-management-package
Or put in your requirements.txt
file-management-package==0.8.1
Usage
Importing the Package
To use the FileManagement class, import it into your project as follows:
from file_management_package.file_management import FileManagement
Example Usage
- Writing to a File:
fm = FileManagement()
fm.write_to_file("Hello, world!", "example.txt")
This will write "Hello, world!" to the file example.txt, creating the file if it does not exist.
If you want a custom file location you need to do this
fm = FileManagement(base_directory="path/to/your/folder")
-
Reading a File Line by Line:
lines = fm.read_file_per_line("example.txt")
print(lines)
This will read the contents of example.txt
and return a list of lines.
-
Check if a File Exists:
file_exists = fm.check_if_file_exists("example.txt")
print(file_exists) # Output: True or False
-
Create a New File:
fm.create_file("new_file.txt")
-
Delete a File:
fm.delete_file("example.txt")
-
Remove Specific Content from a File:
fm.delete_from_file("example.txt", "Hello")
This will remove all lines in example.txt
that contain the word "Hello".
-
Open a File:
fm.open_file("example.txt", is_sdk=False)
This will open example.txt
with the default file handler (e.g., Notepad, TextEdit, etc.).
Error Handling
The FileManagement
class includes robust error handling for:
FileNotFoundError
: If the file is not found.PermissionError
: If there are permission issues.IOError
: General I/O issues with the file system.- General exceptions are caught and handled gracefully.
License
This package is licensed under the MIT License. See the LICENSE file for more details.
Author
Created by Pascal Benink. You can reach me at 2sam2samb+PythonFile@gmail.com.
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 file_management_package-0.8.1.tar.gz
.
File metadata
- Download URL: file_management_package-0.8.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1593b03df96e363d66745334074d4b1936d2ff538e7be2142997c654347b89b8 |
|
MD5 | 3070344e2a34d2ba81515e69ddb97401 |
|
BLAKE2b-256 | 0c4c411e9d13644896710d6f25d4cb84a3702dc884b89b70022213fb99ea327b |
File details
Details for the file file_management_package-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: file_management_package-0.8.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12d75d5f6a177b3f1eccf0cbbe0b574d372f6743615754ae902c00c452cf0bf1 |
|
MD5 | 2b96ae96ab14d80c61557e9063344930 |
|
BLAKE2b-256 | adbf9682617a78146e9fff1b2381f3c8c38265109f9a043ac9a5de845158e1a9 |