Sorry, i'm busy so i can't reply to you quickly !
Just give a try for this modification :
@echo off
Title Search for files and remove lines in text files
mode con cols=75 lines=5 & Color 0A
REM We set the variable Folder with the function Browse4Folder
Call :Browse4Folder "Choose source folder to scan for files" "c:\scripts"
Set "Folder=%Location%"
Rem if the variable %Folder% have a trailing back slash, we remove it !
IF %Folder:~-1%==\ SET "Folder=%Folder:~0,-1%"
If "%errorlevel%" EQU "0" (
echo( & echo(
echo You choose this folder "%Folder%"
Timeout /T 2 /nobreak>nul
) else (
echo( & echo(
echo "%Folder%"
Timeout /T 2 /nobreak>nul & Exit
)
Set "Stop_String=Purpose"
Set "Edited_Files=%HomeDrive%\Edited_Files"
Set "Exceptions_Folder=%HomeDrive%\Exceptions"
If not exist "%Edited_Files%" MD "%Edited_Files%"
If not exist "%Exceptions_Folder%" MD "%Exceptions_Folder%"
SetLocal EnableDelayedExpansion
for /f "delims=" %%f in ('Dir /b /s "%Folder%\*.txt"') Do (
Cls
echo.
set /A "Count=0"
set "InputFile=%%~dpFf"
findstr /I /C:"%Stop_String%" "!InputFile!" >nul 2>&1
If "!ErrorLevel!" EQU "0" (
Call :Counting "%Stop_String%" "!InputFile!"
echo We found the string "%Stop_String%" at line number !Count! on "!InputFile!"
Timeout /T 4 /nobreak>nul
Set "OutPutFile=%Edited_Files%\%%~nxf"
if exist "!OutPutFile!" Del "!OutPutFile!"
Call :Write2File "!InputFile!" "!OutPutFile!"
) else (
Call :Copyfiles "!InputFile!" "!Exceptions_Folder!"
)
)
Rem Explorer "%Edited_Files%" & exit
echo(
set "Title=Search for files and remove lines in text files"
set "Msg=%Title%\nEnd of the script"
Call :Speak "%Msg%"
Rem 64=vbInformation, 48=vbExclamation, 16=vbCritical 32=vbQuestion
Call :MsgBox "%Msg%" 64 "%Title%"
exit
::********************************************************************
:Counting <Stop_String> <InputFile>
For /f "tokens=1 delims=:" %%A in ('findstr /I /N "%~1" "%~2"') Do (
Set /a "Count=%%A"
)
exit /b
::********************************************************************
:Write2File <InputFile> <OutPutFile>
For /f "skip=%Count% delims=*" %%a in ('Type "%~1"') do (
echo %%a >> "%~2"
)
exit /b
::********************************************************************
:Browse4Folder
set Location=
set vbs="%temp%\_.vbs"
set cmd="%temp%\_.cmd"
for %%f in (%vbs% %cmd%) do if exist %%f del %%f
for %%g in ("vbs cmd") do if defined %%g set %%g=
(
echo set shell=WScript.CreateObject("Shell.Application"^)
echo set f=shell.BrowseForFolder(0,"%~1",0,"%~2"^)
echo if typename(f^)="Nothing" Then
echo wscript.echo "set Location=Dialog Cancelled"
echo WScript.Quit(1^)
echo end if
echo set fs=f.Items(^):set fi=fs.Item(^)
echo p=fi.Path:wscript.echo "set Location=" ^& p
)>%vbs%
cscript //nologo %vbs% > %cmd%
for /f "delims=" %%a in (%cmd%) do %%a
for %%f in (%vbs% %cmd%) do if exist %%f del /f /q %%f
for %%g in ("vbs cmd") do if defined %%g set %%g=
goto :eof
::********************************************************************
:Copyfiles <Source> <Target>
Copy /Y "%~1" "%~2" >nul 2>&1
goto :eof
::********************************************************************
:MsgBox <Msg> <Type> <Title>
echo MsgBox Replace("%~1","\n",vbCrLf),"%~2","%~3" > "%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs" & Del "%tmp%\%~n0.vbs"
exit /b
::********************************************************************
:Speak <msg>
(
echo Set sapi=Createobject("sapi.spvoice"^)
echo sapi.Speak("%~1"^)
)>"%tmp%\%~n0.vbs"
Cscript /nologo "%tmp%\%~n0.vbs"
Del "%tmp%\%~n0.vbs"
exit /b
::*********************************************************************