This project is a Python-based script that processes files in a directory, detects text content, and replaces specific words with generic alternatives based on a predefined dictionary. It is designed for portability and ease of use.
- Processes multiple file formats (e.g.,
.txt,.java,.yaml, etc.) in a folder. - Skips empty or non-text files automatically.
- Performs case-insensitive word replacements.
- Dynamically detects the project folder and input files for easy portability.
- Creates the input folder if it doesn't exist.
-
Clone the Repository:
git clone https://github.com/victordrose/replace-word-script cd replace-word-script -
Run the Script:
py gptsafe.py -
Check the Output:
The script will modify the files in place, replacing the specified words.
Update the word_replacements dictionary in the script to define custom words and their replacements:
word_replacements = {
"password": "REDACTED",
"secret": "REDACTED",
"username": "USER",
"email": "EMAIL",
}
Python 3.6 or higher.
project-folder/
│
├── inputs/ # Directory for input files
├── script_name.py # Main Python script
└── README.md # Project documentation
For an input file named input.txt with the content:
username: admin
password: 12345
email: admin@example.com
After running the script, the content will be:
username: USER
password: REDACTED
email: EMAIL