# 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:
```bash
pip install file-management-package
```
Or put in your `requirements.txt`
```txt
file-management-package==0.8.1
```
# Usage
## Importing the Package
To use the FileManagement class, import it into your project as follows:
``` python
from file_management_package.file_management import FileManagement
```
## Example Usage
1. Writing to a File:
``` python
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
``` python
fm = FileManagement(base_directory="path/to/your/folder")
```
2. ### Reading a File Line by Line:
```python
lines = fm.read_file_per_line("example.txt")
print(lines)
```
This will read the contents of `example.txt` and return a list of lines.
3. ### Check if a File Exists:
```python
file_exists = fm.check_if_file_exists("example.txt")
print(file_exists) # Output: True or False
```
4. ### Create a New File:
```python
fm.create_file("new_file.txt")
```
5. ### Delete a File:
```python
fm.delete_file("example.txt")
```
6. ### Remove Specific Content from a File:
```python
fm.delete_from_file("example.txt", "Hello")
```
This will remove all lines in `example.txt` that contain the word "Hello".
7. ### Open a File:
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/Pascal-Benink/File-Management-Package",
"name": "file-management-package",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10.12",
"maintainer_email": null,
"keywords": null,
"author": "Pascal Benink",
"author_email": "2sam2samb+PythonFile@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0c/4c/411e9d13644896710d6f25d4cb84a3702dc884b89b70022213fb99ea327b/file_management_package-0.8.1.tar.gz",
"platform": null,
"description": "# File Management Package\n\n`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.\n\n# Features\n\n- **File Writing**: Write to a file, either appending or writing a single line.\n- **File Reading**: Read a file either line by line or as a whole.\n- **File Existence Check**: Check if a file exists.\n- **File Creation**: Automatically create a file if it doesn't exist.\n- **File Deletion**: Delete a file from the system.\n- **File Content Modification**: Remove specific content from a file.\n- **File Opening**: Open files using the default application for the file type.\n\n# Installation\n\nTo install the package, use the following command:\n\n```bash\npip install file-management-package\n```\nOr put in your `requirements.txt`\n\n```txt\nfile-management-package==0.8.1\n```\n\n# Usage\n## Importing the Package\nTo use the FileManagement class, import it into your project as follows:\n\n``` python\nfrom file_management_package.file_management import FileManagement\n```\n\n## Example Usage\n1. Writing to a File:\n\n``` python\nfm = FileManagement()\nfm.write_to_file(\"Hello, world!\", \"example.txt\")\n```\nThis will write \"Hello, world!\" to the file example.txt, creating the file if it does not exist.\n\nIf you want a custom file location you need to do this\n``` python\nfm = FileManagement(base_directory=\"path/to/your/folder\")\n```\n\n2. ### Reading a File Line by Line:\n\n```python\nlines = fm.read_file_per_line(\"example.txt\")\nprint(lines)\n```\n\nThis will read the contents of `example.txt` and return a list of lines.\n\n3. ### Check if a File Exists:\n\n```python\nfile_exists = fm.check_if_file_exists(\"example.txt\")\nprint(file_exists) # Output: True or False\n```\n\n4. ### Create a New File:\n\n```python\nfm.create_file(\"new_file.txt\")\n```\n\n5. ### Delete a File:\n\n```python\nfm.delete_file(\"example.txt\")\n```\n\n6. ### Remove Specific Content from a File:\n\n```python\nfm.delete_from_file(\"example.txt\", \"Hello\")\n```\n\nThis will remove all lines in `example.txt` that contain the word \"Hello\".\n\n7. ### Open a File:\n\n```python\nfm.open_file(\"example.txt\", is_sdk=False)\n```\n\nThis will open `example.txt` with the default file handler (e.g., Notepad, TextEdit, etc.).\n\n# Error Handling\n\nThe `FileManagement` class includes robust error handling for:\n\n- `FileNotFoundError`: If the file is not found.\n- `PermissionError`: If there are permission issues.\n- `IOError`: General I/O issues with the file system.\n- General exceptions are caught and handled gracefully.\n\n# License\nThis package is licensed under the MIT License. See the LICENSE file for more details.\n\n# Author\nCreated by Pascal Benink. You can reach me at 2sam2samb+PythonFile@gmail.com.\n",
"bugtrack_url": null,
"license": null,
"summary": "A package for file management",
"version": "0.8.1",
"project_urls": {
"Homepage": "https://github.com/Pascal-Benink/File-Management-Package"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "adbf9682617a78146e9fff1b2381f3c8c38265109f9a043ac9a5de845158e1a9",
"md5": "2b96ae96ab14d80c61557e9063344930",
"sha256": "12d75d5f6a177b3f1eccf0cbbe0b574d372f6743615754ae902c00c452cf0bf1"
},
"downloads": -1,
"filename": "file_management_package-0.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b96ae96ab14d80c61557e9063344930",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10.12",
"size": 5678,
"upload_time": "2024-11-07T09:17:38",
"upload_time_iso_8601": "2024-11-07T09:17:38.954955Z",
"url": "https://files.pythonhosted.org/packages/ad/bf/9682617a78146e9fff1b2381f3c8c38265109f9a043ac9a5de845158e1a9/file_management_package-0.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0c4c411e9d13644896710d6f25d4cb84a3702dc884b89b70022213fb99ea327b",
"md5": "3070344e2a34d2ba81515e69ddb97401",
"sha256": "1593b03df96e363d66745334074d4b1936d2ff538e7be2142997c654347b89b8"
},
"downloads": -1,
"filename": "file_management_package-0.8.1.tar.gz",
"has_sig": false,
"md5_digest": "3070344e2a34d2ba81515e69ddb97401",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10.12",
"size": 4776,
"upload_time": "2024-11-07T09:17:39",
"upload_time_iso_8601": "2024-11-07T09:17:39.877889Z",
"url": "https://files.pythonhosted.org/packages/0c/4c/411e9d13644896710d6f25d4cb84a3702dc884b89b70022213fb99ea327b/file_management_package-0.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 09:17:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Pascal-Benink",
"github_project": "File-Management-Package",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "file-management-package"
}