Bat Script replaces the whole line in Config file :
Count Char
:countChar
setlocal
set x=%1
set n=0
set m=255
:loop
if "!x:~%m%,1!" == "" (
set /a "m>>=1"
goto loop
) else (
set /a n+=%m%+1
set x=!x:~%m%!
set x=!x:~1!
if not "!x!" == "" goto loop
)
set /a "rtn=%n"
exit /b %rtn%
setlocal
set x=%1
set n=0
set m=255
:loop
if "!x:~%m%,1!" == "" (
set /a "m>>=1"
goto loop
) else (
set /a n+=%m%+1
set x=!x:~%m%!
set x=!x:~1!
if not "!x!" == "" goto loop
)
set /a "rtn=%n"
exit /b %rtn%
call :countChar %usrname%
echo the answer is %errorlevel%
echo the answer is %errorlevel%
Replace string
GOTO:MAIN
:firstMethodName
SETLOCAL ENABLEDELAYEDEXPANSION
SET seachString=%~1
SET replaceLine=%~2
set finalReplaceLine=%seachString% : %replaceLine%
if exist %target% del %target%
for /F "delims=" %%a in ('type %source%') do (
set line=%%a
echo %%a | find /i "%seachString%" && set line=%finalReplaceLine%
cls
echo !line! >> %target%
)
del Config.txt
rename "Output.txt" "Config.txt"
ENDLOCAL
EXIT /B 0
:MAIN
:firstMethodName
SETLOCAL ENABLEDELAYEDEXPANSION
SET seachString=%~1
SET replaceLine=%~2
set finalReplaceLine=%seachString% : %replaceLine%
if exist %target% del %target%
for /F "delims=" %%a in ('type %source%') do (
set line=%%a
echo %%a | find /i "%seachString%" && set line=%finalReplaceLine%
cls
echo !line! >> %target%
)
del Config.txt
rename "Output.txt" "Config.txt"
ENDLOCAL
EXIT /B 0
:MAIN
call:firstMethodName "User.Name" "%usrname%"
call:firstMethodName "User.Passwod" "%pwd%"
call:firstMethodName "User.Passwod" "%pwd%"
email validation
set /p email="Please enter your email address: "
(echo %email% | findstr "@ [] "%email:~7,1%"==""" >nul 2>&1) && (ECHO valid email >nul) || (echo This is not a valid email address.Please try again.) && GOTO input
echo %inputPath% path does not exist in system. Please check.
SET /p var="Type anything here:"
echo !var!
)
@echo off
SetLocal EnableDelayedExpansion
set source=Config.txt
set target=Output.txt
rem check java version
set JAVAVER=1.0
where java >nul 2>nul
if %errorlevel%==1 (
echo Not able to find java. Please check your Java instalation.
pause
exit
)
for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do (
set JAVAVER=%%g
)
if %JAVAVER% LSS 8.0 (
echo Error : Java version is too low At least Java should be greater then 8.0
pause
exit
)
rem end check java version
:locationPoint
set /p inputPath=Enter Home Location/Path:
if "%inputPath%"=="" (
echo Location/Path should not be empty or blank.
goto locationPoint
)
:userPoint
set /p usrname=Enter User Name:
if "%usrname%"=="" (
echo User Name should not be empty or blank.
goto userPoint
)
:pwdPoint
set /p pwd=Enter Password:
if "%pwd%"=="" (
echo Password should not be empty or blank.
goto pwdPoint
)
rem update user name in Config file
set userSeachString=User.Name
set userReplaceLine=User.Name : %usrname%
if exist %target% del %target%
for /F "delims=" %%a in ('type %source%') do (
set line=%%a
echo %%a | find /i "%userSeachString%" && set line=%userReplaceLine%
echo !line! >> %target%
)
del Config.txt
rename "Output.txt" "Config.txt"
rem update password in Config file
set pwdSeachString=User.Passwod
set pwdReplaceLine=User.Passwod : %pwd%
if exist %target% del %target%
for /F "delims=" %%a in ('type %source%') do (
set line=%%a
echo %%a | find /i "%pwdSeachString%" && set line=%pwdReplaceLine%
echo !line! >> %target%
)
del Config.txt
rename "Output.txt" "Config.txt"
rem copy Config file in destinaion folder
xcopy /s Config.txt %inputPath%
Config File :
Domain Name : https://abhishekdevelopment.blogspot.com/ User.Name : abhishek User.Passwod : xxxxxx SMTP : smtp
Comments
Post a Comment