That's excellent! Since your mini-project is a Python CLI utility for File and Exception Handling using the pathlib
and os
modules, I'll generate a tailored README file for it.
This README focuses on the purpose of the project, how to run it, and highlights the core concepts it demonstrates.
This project is a Mini-Project demonstrating fundamental Python concepts in File Handling and Exception Management. It provides a simple Command Line Interface (CLI) that allows a user to perform basic CRUD (Create, Read, Update, Delete) operations on files within the current directory.
The primary goals of this utility are to illustrate:
- File Handling: Using Python's built-in
open()
function with various modes ('w'
,'r'
,'a'
). - Path Management: Leveraging the modern
pathlib.Path
module for robust file system interactions (checking existence, renaming, and reading file information). - Exception Handling: Implementing
try...except
blocks to gracefully manage common errors likeFileNotFoundError
,PermissionError
, and invalid user input (ValueError
).
- Python 3.x
pathlib
(Standard Library)os
(Standard Library)
Follow these steps to get a copy of the project running on your local machine.
You only need Python 3.8 or newer installed on your system.
- Clone the repository:
git clone https://github.com/gitdhruv-tech/CRUD-on-File.git
- Navigate to the project directory:
cd CRUD-on-File
- Ensure the main script is present: The file containing the code (e.g., main.py or similar) should be in this directory.
Run the script directly from your terminal. The application will start and present the main menu.
python main.py
The utility provides the following functions:
Menu Option | Function | Demonstrates |
---|---|---|
1 | Create a file | Using open(..., 'w') and path existence checks. |
2 | Read a file | Using open(..., 'r') and handling FileNotFoundError . |
3 | Update a file | File renaming (.rename() ), content overwriting ('w' ), and appending ('a' ). |
4 | Delete a file | Using Path.unlink() or os.remove() to delete a file. |
5 | Exit | Terminates the program loop. |
Note: All file operations are performed relative to the directory where you execute the script.
This is a mini-project focused on fundamental concepts. However, suggestions for improving the code's robustness, adding better input validation, or using more specific exception types are welcome!
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/better-validation
). - Commit your Changes (
git commit -m 'Refactor: Improved input validation in main menu'
). - Push to the Branch (
git push origin feature/better-validation
). - Open a Pull Request.
Distributed under the MIT License. See LICENSE
for more information.
Dhruv Maheshwari - dhruv.mahe.003@gmail.com
Project Link: https://github.com/gitdhruv-tech/CRUD-on-File