๐Ÿ Lesson 29: Python Automation – Automate Files, Folders, Emails & More

Welcome to Lesson 29! Today we’ll explore how Python can automate daily tasks — file management, sending emails, working with folders, and more. Automation helps you save time, remove repetitive work, and build powerful scripts for real-world usage.


๐Ÿ’ก Quick Benefits of Python Automation

  • Save hours of repetitive work
  • Automate daily office tasks (files, emails, screenshots)
  • Automate reports, data collection, and emails
  • Build powerful bots and assistants for personal or work use
  • Control your computer programmatically for streamlined workflows

๐Ÿ—‚ 1. Automating Files & Folders

๐Ÿ“ฆ Create Folders Automatically


import os

os.makedirs("my_folder", exist_ok=True)
print("Folder created!")

๐Ÿ“ฆ List All Files in a Directory


import os

files = os.listdir(".")
print(files)

๐Ÿ“ฆ Moving & Renaming Files


import os

os.rename("old.txt", "new.txt")
print("File renamed!")

๐Ÿ“ง 2. Sending Emails with Python

Use Python’s smtplib module to send emails.


import smtplib

sender = "youremail@example.com"
password = "YOUR_PASSWORD"
receiver = "friend@example.com"

message = """Subject: Hello from Python
This email was sent using Python automation!
"""

with smtplib.SMTP("smtp.gmail.com", 587) as server:
    server.starttls()
    server.login(sender, password)
    server.sendmail(sender, receiver, message)

print("Email sent!")

Note: Gmail requires special app passwords or security settings.


๐Ÿ“„ 3. Reading Text from PDFs


pip install PyPDF2

import PyPDF2

with open("example.pdf", "rb") as file:
    reader = PyPDF2.PdfReader(file)
    text = reader.pages[0].extract_text()
    print(text)

๐Ÿ–ผ 4. Automating Screenshots


pip install pyautogui

import pyautogui

screenshot = pyautogui.screenshot()
screenshot.save("screenshot.png")

๐ŸŒ 5. Automating Website Actions

Using Selenium, you can automate clicking, typing, scraping, and browsing.


pip install selenium

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://google.com")
print(driver.title)

๐Ÿง  Why Python Automation Is Powerful

  • Save hours of repetitive work
  • Automate office tasks
  • Automate email reports
  • Build bots and assistants
  • Control your computer programmatically

๐Ÿงช Practice

  1. Create a script that renames all files in a folder.
  2. Write a program that takes a screenshot every 10 seconds.
  3. Automate sending an email (use a test email for safety).
  4. Extract text from a PDF and save it into a text file.

❓ Common Mistakes

  • Forgetting to handle errors in file operations (e.g., missing files or permissions)
  • Not setting proper security settings when sending emails (e.g., app passwords)
  • Overcomplicating the script—keep automation tasks simple and efficient

❓ Frequently Asked Questions (FAQ)

1. How do I use automation for file management?

Automation can be used to organize files, rename, move, or delete them based on specific conditions or tasks.

2. Can I automate sending emails with attachments?

Yes! You can use Python’s smtplib along with email.mime to send emails with attachments. It is great for automating reports or newsletters.

3. How can I automate web actions?

You can use the selenium library to control a web browser, fill out forms, scrape data, and more.


๐Ÿš€ What’s Next?

In the next lesson, you’ll learn how to:

  • Create a project that utilizes automation to interact with websites
  • Learn how to build bots that automate repetitive tasks

➡ Next Lesson

Go to Lesson 30 →

Comments

Popular posts from this blog

How to Install Geany 2.1 on Windows 10/11 (2026) | Step-by-Step Guide

How to Uninstall Bluefish 2.2.19 on Windows 10/11 (2026) | Step-by-Step Guide

How to Install Visual Studio 2026 on Windows 10/11 | Step-by-Step Guide