Advertisement
Python253

get_pwnd

Jun 21st, 2024
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: get_pwnd.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script recursively renames all files in a specified directory and its subdirectories.
  10.    - It does this by stripping their existing extensions and appending '.pwnd'.
  11.    - It skips renaming files with a '.py' extension and leaves directory names unchanged.
  12.  
  13. Requirements:
  14.    - Python 3.x
  15.    - os module
  16.  
  17. Functions:
  18.    - add_pwnd_extension(directory):
  19.        Recursively renames files by appending '.pwnd' to their base names, excluding '.py' files.
  20.  
  21. Usage:
  22.    - Ensure Python 3.x is installed.
  23.    - Run the script in a directory where files need to be renamed.
  24.    - The script will rename all files in the current directory and its subdirectories.
  25.  
  26. Additional Notes:
  27.    - Files with conflicting names will have a numeric suffix added (e.g., filename_1.pwnd).
  28.    - Ensure the script is run with appropriate permissions to rename files.
  29. """
  30.  
  31. import os
  32.  
  33. def add_pwnd_extension(directory):
  34.     """
  35.    Recursively renames all files in the specified directory and its subdirectories by
  36.    stripping their existing extensions and appending '.pwnd'.
  37.  
  38.    Files with a '.py' extension are excluded from renaming. Directory names remain unchanged.
  39.  
  40.    Args:
  41.    directory (str): The path to the directory where the renaming should begin.
  42.  
  43.    Returns:
  44.    None
  45.    """
  46.     for root, _, files in os.walk(directory):  # Use underscore for the unused 'dirs' variable
  47.         for filename in files:
  48.             if filename.endswith('.py'):
  49.                 continue  # Skip .py files
  50.  
  51.             old_path = os.path.join(root, filename)
  52.             base_filename = os.path.splitext(filename)[0]  # Remove the existing extension
  53.             new_filename = base_filename + '.pwnd'  # Append the new '.pwnd' extension
  54.             new_path = os.path.join(root, new_filename)
  55.  
  56.             # Check if the new file path already exists and handle conflicts
  57.             counter = 1
  58.             while os.path.exists(new_path):
  59.                 new_filename = f"{base_filename}_{counter}.pwnd"
  60.                 new_path = os.path.join(root, new_filename)
  61.                 counter += 1
  62.  
  63.             os.rename(old_path, new_path)
  64.             print(f"\nPWND:\n{old_path}\n   --->\t--->\t--->\t-P->\t-W->\t-N->\t-D->\t--->\t--->\t--->\n{new_path}")
  65.  
  66. if __name__ == "__main__":
  67.     """
  68.    Main execution block. Gets the current working directory and initiates the renaming process.
  69.    """
  70.     cwd = os.getcwd()
  71.     add_pwnd_extension(cwd)
  72.     print("\n\n\t\t\t\tYOU HAVE BEEN PWND!\n\n\t\t\tALL YOUR FILES IS BELONG TO US NOW!")
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement