This project replaces text in files based on a dictionary, given user input to specify which direction (keys-to-values or values-to-keys).
- Replace text in files based on dictionaries defined in a configuration file.
- Allows user to specify the direction of replacement (keys-to-values or values-to-keys).
- Allows user to specify which file extensions, file prefixes, or directories to ignore.
- Automatically uses the only dictionary if only one is defined in the configuration file.
- Python 3.8 or higher
- Poetry package manager
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
-
Clone the repository and navigate to the project directory:
git clone https://github.com/cainky/ReplaceText.git cd ReplaceText
-
Install dependencies:
poetry install
-
Rename the example configuration file:
mv example_config.json config.json
-
Edit
config.json
to define your dictionaries. Here is an example{ "dictionaries": { "example1": { "key1": "value1", "key2": "value2", "key3": "value3" }, "example2": { "hello": "world", "foo": "bar", "python": "rocks" } }, "ignore_extensions": [".exe", ".dll", ".bin"], "ignore_directories": ["node_modules", "venv", ".git"], "ignore_file_prefixes": [".", "_"] }
Run the script using Poetry:
poetry run python replace_text/replace_text.py
The script will prompt you for the following inputs:
Direction of replacement:
- Enter '1' for keys-to-values
- Enter '2' for values-to-keys
Folder path:
- Enter the path to the folder containing the files to be processed.
Dictionary name:
- Enter the name of the dictionary to use from config.json. The script will process all files in the specified folder, replacing text based on the selected dictionary and direction.
ReplaceText is distributed under the GNU General Public License, Version 3, allowing for free software distribution and modification while ensuring that all copies and modified versions remain free.