Skip to content

Commit afcd3ea

Browse files
Create Script.py
1 parent c0b68a7 commit afcd3ea

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Automated Script/Script.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import shutil
3+
4+
def automated_backup(source_dir, destination_dir):
5+
try:
6+
# Check if the source directory exists
7+
if not os.path.exists(source_dir):
8+
print(f"Source directory '{source_dir}' does not exist.")
9+
return
10+
11+
# Create the destination directory if it doesn't exist
12+
os.makedirs(destination_dir, exist_ok=True)
13+
14+
# Copy files and folders from source to destination
15+
for root, dirs, files in os.walk(source_dir):
16+
for file in files:
17+
source_file = os.path.join(root, file)
18+
destination_file = os.path.join(destination_dir, os.path.relpath(source_file, source_dir))
19+
shutil.copy2(source_file, destination_file)
20+
21+
print("Backup completed successfully!")
22+
except Exception as e:
23+
print(f"An error occurred during backup: {e}")
24+
25+
if __name__ == '__main__':
26+
source_directory = input("Enter the source directory to be backed up: ")
27+
destination_directory = input("Enter the destination directory for the backup: ")
28+
29+
automated_backup(source_directory, destination_directory)
30+
'''
31+
To use the script, copy the code into a Python file (e.g., backup_script.py) and run it using a Python interpreter. The script will prompt you to enter the source and destination directories. After entering the directories, it will initiate the backup process and copy the files and folders from the source directory to the specified destination directory.
32+
'''

0 commit comments

Comments
 (0)