Skip to main content

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.0

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

  1. 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.

  1. 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.

  1. Check if a File Exists:

file_exists = fm.check_if_file_exists("example.txt")
print(file_exists)  # Output: True or False
  1. Create a New File:

fm.create_file("new_file.txt")
  1. Delete a File:

fm.delete_file("example.txt")
  1. 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".

  1. 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

file_management_package-0.8.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

file_management_package-0.8.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file file_management_package-0.8.0.tar.gz.

File metadata

File hashes

Hashes for file_management_package-0.8.0.tar.gz
Algorithm Hash digest
SHA256 06f8374042af5551c42835b6b280843af1c293b7b08bba989e8728d4ce953e24
MD5 b77245b9f63bf8c6d126304ee717e410
BLAKE2b-256 6db35d76cd1d23d8370e2f8ab93e61b166d0a2ec61b4332670ece48691a75e28

See more details on using hashes here.

File details

Details for the file file_management_package-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for file_management_package-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51c363d1fbf249b843eaeee99df7def3b9e7f3ebd714361092c7e97484ccffd1
MD5 c48ffaec9b35222ca88cd151ed2e5d42
BLAKE2b-256 b580759694c30eaeb8e80bd8dcecc22e5aa5e0e4d755327ef18d8baea22e1d80

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page