Batch script to check an entry exist or not and update the file

Click to rate this tutorial!
[Total: 0 Average: 0]

Batch script to check whether a particular entry exist or not and update the file.We are taking backup of the original file and then editing it.

@echo off
REM check for existence of the file
if not exist %SystemRoot%\my_data (echo my_data FILE DOES NOT EXIST
call :not_exist)
REM check for existence of the entry
find /c /i "121.0.0.1" "%SystemRoot%\my_data" > NUL
if %ERRORLEVEL% equ 0 (
echo the entry [Mistonline] for data file already exists.Exiting from the process.
echo Seems like you have already ran this script.
ping 1.0.0.0 -n 1 -w 3000 >NUL
exit
) else (
REM add the entry
type %SystemRoot%\my_data >%SystemRoot%\my_data_bkp
echo Username Mistonline.        #My Local Site >>%SystemRoot%\my_data
echo This window will close automatically.
echo Updation Completed Succesfully.
ping 1.0.0.0 -n 1 -w 5000 >NUL
exit
)
:not_exist
echo File is not found on your machine.Please contact the admin or check in your windows directory.
ping 1.0.0.0 -n 1 -w 3000 >NUL
exit

Here we are editing the file and updating it accordingly.

Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published.