diff --git a/backup saver/backup_saver.py b/backup saver/backup_saver.py new file mode 100644 index 00000000..dd3c152d --- /dev/null +++ b/backup saver/backup_saver.py @@ -0,0 +1,24 @@ +import os +import shutil +def backup(source,destination): + if( os.path.exists(source)): + print("the file has been found") + else: + raise FileNotFoundError() + + if (os.path.exists(destination)): + print("the directory exists") + else: + os.mkdir(destination) + + try: + shutil.copy2(source,destination) + print("file copied successfully") + except Exception as e: + print(f"error during backup {e}") + +source1=input("Enter the path of the file you want to save") +destination1=input("Enter the destination directory for the backup") +backup(source1,destination1) + + diff --git a/backup saver/readme.md b/backup saver/readme.md new file mode 100644 index 00000000..2fe3e1e9 --- /dev/null +++ b/backup saver/readme.md @@ -0,0 +1,13 @@ +# 📂 Python File Backup + +Backup files using Python's built-in `os` and `shutil`. + +## ✨ Features +* **Auto-Folder:** Creates the backup directory if missing. +* **Metadata:** Keeps original file dates intact using `shutil.copy2`. +* **Validation:** Checks if the source file exists. + +## 🚀 How to Use +1. Run: `python backup_script.py` +2. Enter the source path. +3. Enter the destination path.