Yzöwl Posted November 8, 2011 Share Posted November 8, 2011 You don't even need to use find if you only have one line under a single section heading.Type this single line into a console window to see what I mean:FOR /F "USEBACKQ EOL=[ TOKENS=*" %# IN ("X:\PATH TO\DIRECTORY\FOLDERSTROE.INI") DO @ECHO=%#Obviously you'll need to change the path accordingly. Link to comment Share on other sites More sharing options...
jaclaz Posted November 8, 2011 Share Posted November 8, 2011 You don't even need to use find if you only have one line under a single section heading.Type this single line into a console window to see what I mean:FOR /F "USEBACKQ EOL=[ TOKENS=*" %# IN ("X:\PATH TO\DIRECTORY\FOLDERSTROE.INI") DO @ECHO=%#Obviously you'll need to change the path accordingly.Yep But, since we are going to read a very simple file, made of two lines, of which we are interested in the second only, we can also skip the first one.@allen2Of course it is presumed that no Cabfolder1 environment variable is present, please note how your remark also applies to the original "value1" or, for that matter, for any variable name, theoretically you need to do error checking EVERY time you define a variable to see if it is already defined or use a LOCAL statement (or use XSET for an opposite behaviour), etc., etc.@echo offSETLOCALFOR /F "USEBACKQ skip=1 tokens=1,2 delims==" %%A IN ("folderstore.ini") DO IF NOT DEFINED %%A SET "%%A=%%B"&IF NOT DEFINED %%A SET /P %%A=Path to your cabfolder: the above won't touch a pre-existing variable, but obviously IF the variable is already defined, it won't be of ANY use.This might be more effective (just an idea):@echo offSETLOCAL ENABLEDELAYEDEXPANSIONSET #a_h1ghl1_1mprob@bl3_v@r1@bl3_n@m3=NOFOR /F "USEBACKQ skip=1 tokens=1,2 delims==" %%A IN ("folderstore.ini") DO (IF DEFINED %%A (ECHO Dear demented USER, the variable %%A IS ALREADY DEFINED!SET %%AECHO.SET /P #a_h1ghl1_1mprob@bl3_v@r1@bl3_n@m3=Type YES - CAPITAL LETTERS - to change it's value to "%%B" or press [ENTER] to leave it alone: ) ELSE (SET #a_h1ghl1_1mprob@bl3_v@r1@bl3_n@m3=YES)IF "!#a_h1ghl1_1mprob@bl3_v@r1@bl3_n@m3!"=="YES" SET "%%A=%%B"&IF NOT DEFINED %%A SET /P %%A=Path to your cabfolder: )jaclaz Link to comment Share on other sites More sharing options...
Geej Posted November 9, 2011 Author Share Posted November 9, 2011 FOR /F "TOKENS=1* DELIMS==" %%# IN ( 'FIND "Cabfolder1"^<FOLDERSTORE.INI 2^>NUL') DO SET "VAL1=%%$"Hi, YzöwlI was trying to understand your script in post#6 and was wondering what does it means when you use %%#and %%$If I tried replacing with normal variable like%%A for %%# and %%B for %%$surprising it returns correctly the result.And looking at the ascii table,the next character after # is $,just like next character after A is B.Is there other special consideration when you use # and $ as variable?Will simple character like A and B achieve exactly the same result?So I can generally use special character as variable, just like you did? Link to comment Share on other sites More sharing options...
Yzöwl Posted November 9, 2011 Share Posted November 9, 2011 It's just my personal preference, I use them in exactly the same way as you use A and B, I just find that they stand out better than all of the other A's and B's for example. Link to comment Share on other sites More sharing options...
jaclaz Posted November 9, 2011 Share Posted November 9, 2011 Just for the record:http://www.robvanderwoude.com/clevertricks.phpscroll down until you find "Carlos M. found a way to increase the number of variables available in a FOR /F loop" that explains partially the thingy.The real issue wich I can see with using the additional # and $ is that the NEXT characters are %, &, etc. that would need to be escaped, so they are a very nice choice if you only have 2 tokens, but they may become a problem if you need 3 or more. jaclaz Link to comment Share on other sites More sharing options...
Geej Posted November 10, 2011 Author Share Posted November 10, 2011 Thanks for the clarification, Yzowl. I prefer conventional variable.Jaclaz, thanks for the trick links. Looks pretty interesting. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now