Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: take_out_the_trash.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script provides functionality to manage the recycle bin, including listing its contents and emptying it.
- Requirements:
- - Python 3.x
- - Windows operating system
- Functions:
- - list_trash(): Lists the contents of the recycle bin.
- - empty_trash(): Empties the recycle bin.
- - main(): Main function to execute the script.
- Usage:
- 1. Ensure Python 3.x is installed on your system.
- 2. Run the script using the command: python take_out_the_trash.py
- 3. Follow the prompts to view recycle bin contents and empty it if desired.
- Additional Notes:
- - The script uses ctypes and win32com modules, which are specific to Windows.
- - It prompts the user to confirm before emptying the recycle bin.
- - If the recycle bin is already empty, it displays an appropriate message.
- """
- import ctypes
- from win32com.client import Dispatch
- def list_trash():
- """
- Lists the contents of the recycle bin.
- """
- shell = Dispatch("Shell.Application")
- trash = shell.Namespace(10)
- items = trash.Items()
- print("Contents:")
- for item in items:
- print(item.Name)
- def empty_trash():
- """
- Empties the recycle bin.
- """
- # Define the SHEmptyRecycleBin function signature
- SHEmptyRecycleBin = ctypes.windll.shell32.SHEmptyRecycleBinW
- # Set flags for the function call
- SHERB_NOCONFIRMATION = 0x1
- dwFlags = SHERB_NOCONFIRMATION
- # Call the SHEmptyRecycleBin function to empty the recycle bin
- res = SHEmptyRecycleBin(None, None, dwFlags)
- if res != 0:
- # If the function call returns a non-zero value, handle the error
- error_message = ctypes.FormatError(res)
- print(f"\nError 0x{res:08x} - OSCAR THE GROUCH SAYS: {error_message}!\n\t- It seems the recycle bin was already empty -\n\n\tExiting Program...\tGoodBye!\n")
- exit(res)
- else:
- print("\nThe trash has been taken out!\n")
- def main():
- """
- Main function to execute the script.
- """
- # List contents of recycle bin
- list_trash()
- # Ask user if they want to empty the recycle bin
- choice = input("\nDo you want to take out the trash?\n\n1: Yes\n0: No\n\nMake your selection (1 or 0): ")
- if choice == "1":
- # Empty the recycle bin
- empty_trash()
- elif choice == "0":
- print("\n\tNo action taken. Exiting Program...\tGoodBye!\n")
- else:
- print("\nInvalid choice. Please enter '1' or '0'.\n")
- # Call the main function
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement