From e5db88108e074bd6c4cc7dbe3462bda92f0e8d28 Mon Sep 17 00:00:00 2001 From: Fleischkuechle Date: Sun, 19 May 2024 15:57:59 +0200 Subject: [PATCH] added a py file search and replace string bat script --- ...o_Search_Replace_a_string_in_a_Py_file.bat | 175 ++++++++++++++++++ ...h_Replace_a_string_in_a_Py_file_example.py | 8 + ...m_input_to_output_with_excludetxt copy.bat | 0 ...h_Replace_a_string_in_a_Py_file_example.py | 16 ++ 4 files changed, 199 insertions(+) create mode 100644 10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file.bat create mode 100644 10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py rename 9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt.bat => 9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt copy.bat (100%) create mode 100644 testing/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py diff --git a/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file.bat b/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file.bat new file mode 100644 index 0000000..e1c91b5 --- /dev/null +++ b/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file.bat @@ -0,0 +1,175 @@ + + +@echo off +REM this is getting the path where the bat file is. +cd /D "%~dp0" +setlocal enabledelayedexpansion + +@REM set "search_sentence=This is the old sentence." +@REM set "replace_sentence=This is the new sentence." + +set search_sentence=Is_development:bool=True +set replace_sentence=Is_development:bool=False +@REM set file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py +@REM set temp_file=temp.py + +set "file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py" +set "temp_file=temp.py" + +(for /f "tokens=*" %%a in ('type "%file_path%"') do ( + set "line=%%a" + set "trimmed_line=!line: =!" + set "trimmed_search=!search_sentence: =!" + if "!trimmed_line!"=="!trimmed_search!" ( + echo %replace_sentence% + ) else ( + echo !line! + ) +)) > "%temp_file%" + +move /y "%temp_file%" "%file_path%" + + + + + + + + + + + + + + +@REM @echo off +@REM setlocal enabledelayedexpansion + +@REM REM this is getting the path where the bat file is. +@REM cd /D "%~dp0" +@REM set search_sentence=Is_development:bool=True +@REM set replace_sentence=Is_development:bool=False + +@REM set file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py +@REM set temp_file=temp.py + +@REM (for /f "tokens=*" %%a in ('type "%file_path%"') do ( +@REM set "line=%%a" +@REM set "trimmed_line=!line: =!" +@REM set "trimmed_search=!search_sentence: =!" +@REM set "output_line=" + +@REM :replace_loop +@REM if "!line: %search_sentence%=!" neq "!line!" ( +@REM set "line=!line:%search_sentence%=%replace_sentence%!" +@REM set "output_line=!output_line!!replace_sentence!" +@REM goto replace_loop +@REM ) + +@REM if defined output_line ( +@REM echo !output_line! +@REM ) else ( +@REM echo !line! +@REM ) +@REM )) > "%temp_file%" + +@REM move /y "%temp_file%" "%file_path%" + + + + + + + + +@REM @echo off +@REM setlocal enabledelayedexpansion + +@REM set search_sentence=Is_development:bool=True +@REM set replace_sentence=Is_development:bool=False + +@REM set file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py +@REM set temp_file=temp.py + +@REM (for /f "tokens=*" %%a in ('type "%file_path%"') do ( +@REM set "line=%%a" +@REM set "trimmed_line=!line: =!" +@REM set "trimmed_search=!search_sentence: =!" +@REM if "!trimmed_line!"=="!trimmed_search!" ( +@REM echo %replace_sentence% +@REM ) else ( +@REM echo !line! +@REM ) +@REM )) > "%temp_file%" + +@REM move /y "%temp_file%" "%file_path%" + + + + + + + + + + + + + + + + + + + + + +@REM @echo off +@REM setlocal enabledelayedexpansion + +@REM REM this is getting the path where the bat file is. +@REM cd /D "%~dp0" + +@REM set search_sentence=Is_development:bool=True +@REM set replace_sentence=Is_development:bool=False + +@REM set file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py +@REM set temp_file=temp.py + +@REM (for /f "tokens=*" %%a in ('type "%file_path%"') do ( +@REM set "line=%%a" +@REM if "!line!"=="%search_sentence%" ( +@REM echo %replace_sentence% +@REM ) else ( +@REM echo !line! +@REM ) +@REM )) > "%temp_file%" + +@REM move /y "%temp_file%" "%file_path%" + + + + + + + +@REM @echo off +@REM @echo off +@REM setlocal enabledelayedexpansion +@REM REM this is getting the path where the bat file is. +@REM cd /D "%~dp0" + +@REM set search_text=Is_development:bool=True +@REM set replace_text=Is_development:bool=False + +@REM set path=%CD% +@REM set file_path=%CD%\10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py +@REM set "temp_file=temp.py" + +@REM (for /f "tokens=*" %%a in ('type "%file_path%"') do ( +@REM set "line=%%a" +@REM set "line=!line:%search_text%=%replace_text%!" +@REM echo !line! +@REM )) > "%temp_file%" + +@REM move /y "%temp_file%" "%file_path%" \ No newline at end of file diff --git a/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py b/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py new file mode 100644 index 0000000..137fd9b --- /dev/null +++ b/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py @@ -0,0 +1,8 @@ +Is_development:bool=True +Is_development:bool=True +Is_development:bool=True +Is_development:bool=True +Is_development:bool=True +Is_development:bool=True +Is_development:bool=True Is_development:bool=True Is_development:bool=True +Is_development:bool=True diff --git a/9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt.bat b/9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt copy.bat similarity index 100% rename from 9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt.bat rename to 9_Double_Click_Me_To_COPY_all_files_from_input_to_output_with_excludetxt copy.bat diff --git a/testing/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py b/testing/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py new file mode 100644 index 0000000..b035a85 --- /dev/null +++ b/testing/10_Double_Click_Me_To_Search_Replace_a_string_in_a_Py_file_example.py @@ -0,0 +1,16 @@ +import bpy + + + + + +Is_development:bool=True + + +Is_development:bool=True + + +Is_development:bool=True + + +Is_development:bool=True Is_development:bool=True Is_development:bool=True \ No newline at end of file