Thanks for all the suggestions. I tested them using 3 scenarios
(1. Folder with space, 2. Folder no space, 3. Empty folder (ie. empty string))
I changed folderstore.ini to below so that I can easily modify the seach key to test all 3 situations.
[Directory]
Cabfolder1=C:\Documents and Settings\user name\My Documents
Cabfolder2=C:\Documents_and_Settings\user_name\My_Documents
Cabfolder3=
@allen2
Appreciate your input. Notice the output string is always quoted.
(I hope not to have it quoted.). If I change
(set value1="%%i")
to
(set value1=%%i) and rerun, the script terminate abnormally.
I wonder why terminate abnormally? Perhaps this line is causing problem:- if %value1%==""
Also if cabfolder3= (contains empty entry), the script terminate abruptly.
(I presume you did not check this part for empty folder)
You have remove the need for temp file : %txt1%. (I couldn't figure out how to do it w/o temp file.)
@gunsmokingman
Thanks for the alternative. Although your script looks for "Cabfolder1", it returns the value of Cabfolder2.
Suppose I add an extra line to folderstore.ini to test for empty string/path,
and I specify "Cabfolder2" within the script, it return Cabfolder3 value. Or do I miss out something?
Normally the expected output is the string on the right only. The script rtn the whole line, including strings on the left.
@Schiiwa
Achieve what I set out to do in all 3 scenarios (Folder with space, folder no space, empty string).
Thanks. I didn't know how to use If not defined syntax. I guess the scenario illustrate how to use this syntax.
Combining allen2's & Schiiwa's input, (because %txt1% is not required and Schiiwa fixed the problem by using If not defined rather than if %value1%=="",
so the final script I adopt is
@echo off
Set inifile=folderstore.ini
FOR /F "delims== tokens=2* usebackq" %%i in (`type %inifile% ^| find "Cabfolder3="`) do (set value1=%%i)
If not defined VALUE1 (color 1A && echo Folder path not defined.) else (Echo %value1%)
echo.
pause
@jaclaz
Thanks for the link. Will read up on For /F [option] parameters.
If you have other useful links, do pass on.
Also it's not that I'm re-inventing the wheel but the script out there are fairly advanced for my humble knowledge to
easily adapt for my use.
I believe if I code it first I will appreciate and learn better the batch language.
@Yzowl
Thanks, yes, fits what I need. Perfect.
I could have easily script using Autoit but I just wish to experience using pure batch to see how difficult or easy to do such simple task.
Apparently, looking at the solution .... doesn't look easy after all.
But it's all for the sake of knowledge, esp For loop command.
They are the bread and butter of cmd syntax to be really useful.
Thank you all.
Best regards