Solved How can I use a txt file as a phonebook with a BatScript?

August 21, 2016 at 11:12:17
Specs: Windows 64
I have a .txt file as a phonebook database. How can I create a bat script to ask for a Name and read the information from the .txt file? Can you please help me?

See More: How can I use a txt file as a phonebook with a BatScript?

Report •

August 21, 2016 at 21:57:02
✔ Best Answer
I have used this, both for phone numbers and for "general notes" to myself. Recommend DO NOT include any passwords or sensitive data.
::------ begin batchscript PHONES.bat
@echo off & setlocal
:: ---- LOCAL SETTING for your PHONES text file path and name
set phones=c:\directory\phones

set string=
set string=%*
if not defined string set string=""
:: strip quotes cause don't know if there are any were included in argument
set string=%string:"=%
:: add them back to encapsulate search string for FIND
set string="%string%"
:: if no argument, default to EDIT
if %string% equ "" (
edit %phones%
) else (
echo searching for string: %string% in file: %phones%
echo ------------------------------------
find /i %string%<%phones%||(
echo string not found.
goto :eof
::---- end script
for sensitive data, use encryption/decryption with password.
PS: this uses commandline arguments to search for. If you want it prompted, replace this line: set string=%*
with: set /p string=Enter search string:
I think that should work.

message edited by nbrane

Report •
Related Solutions

Ask Question