someuser77 Posted May 29, 2005 Share Posted May 29, 2005 i would like to create arrays in a batch program, i added all the data as:arr[1]arr[2]arr[3]...but the output is the tough part, i used: set n=2echo %arr[%n%]%but that didnt work. is there anything i can do?my idea is to write a file list into that array, then pointing to one of the files.i really dont want to create temp files for this job. Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 29, 2005 Share Posted May 29, 2005 Cmd promt I believe cannot handle arrays VBS does handle arrarys.Note : Arrays always start at ZeroExample = Array("Some Message", "Some Text", "More Of Whatever","Test Array")Msgbox Example(0) & vbcrlf & Example(1) & vbcrlf & Example(2), 0 + 32, Example(3) Link to comment Share on other sites More sharing options...
someuser77 Posted May 29, 2005 Author Share Posted May 29, 2005 cant i write a variable name using a variable? like in PHP? Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 29, 2005 Share Posted May 29, 2005 I do not know about php, but you can use varibles in cmd.Echo Off && CLS && Mode 55,5 && Color 5eSet Var1=Hello WorldSet Var2=ping -n 3 127.0.0.1Set Var3=Good Bye Echo.echo %Var1%%Var2%>nulecho.echo %Var3%%Var2%>nulexit Link to comment Share on other sites More sharing options...
someuser77 Posted May 30, 2005 Author Share Posted May 30, 2005 for %%G in (%location%\*.txt) do (set /a count+=1call :exec1 %%~nGecho %%~nG)goto :continue1:exec1echo %count%set mapArray[%count%]=%1goto :end:continue1:endthis is what i have so far, the idea is to point to an array number (mapArray[1]) and return the file name.i will ask for a number input, and return the file name. Link to comment Share on other sites More sharing options...
Martin Zugec Posted May 30, 2005 Share Posted May 30, 2005 Mine is similar Set strArrayNumber=0For /f "usebackq" %%i IN (`type test.txt`) DO ( Set strArrayValue=%%i call:functionArray )Goto :EOF:functionArrayset /a strArrayNumber=%strArrayNumber% + 1set strArrayName.%strArrayNumber%=%strArrayValue%Goto :EOF Link to comment Share on other sites More sharing options...
someuser77 Posted May 30, 2005 Author Share Posted May 30, 2005 looks good! but how do i work with it next?echo %strArrayName.%strArrayNumber%%how do i output strArrayName.strArrayNumber? Link to comment Share on other sites More sharing options...
Martin Zugec Posted May 30, 2005 Share Posted May 30, 2005 echo %strArrayName.1%will show first entry in array... Variable %strArrayNumber% shows total number of array entries Link to comment Share on other sites More sharing options...
someuser77 Posted May 30, 2005 Author Share Posted May 30, 2005 yes, but is there a way to write the "1" as a variable, so it can be processed in a loop? Link to comment Share on other sites More sharing options...
Martin Zugec Posted May 30, 2005 Share Posted May 30, 2005 I use it like For /f "usebackq delims==. tokens=1-3" %%i IN (`set strArrayName`) DO Echo Array field number %%j have value %%k Link to comment Share on other sites More sharing options...
someuser77 Posted May 30, 2005 Author Share Posted May 30, 2005 thanks soulin! works like magic! Link to comment Share on other sites More sharing options...
Martin Zugec Posted May 30, 2005 Share Posted May 30, 2005 I am proudly serving my masters BTW If you are intrested in batches, sometimes you can find something useful in my blog. Link to comment Share on other sites More sharing options...
JoeMSFN Posted June 8, 2005 Share Posted June 8, 2005 (edited) WOW!!! I just stumbled upon this thread quite accidentally (forgot the original search.. more of a tangent.. funny how the net works like that )@Martin ZugecThank you for this snippet:set /a strArrayNumber=%strArrayNumber% + 1@someuser77Thank you for this snippet:set /a count+=1I've been doing the "just google it, you'll find it" and havent found squat... my interest was how to "increment an environment variable". You guys have answered a question I've had for about half a week. I didn't even realize there was more to this place than Unattended CDs! Edited June 8, 2005 by JoeMSFN Link to comment Share on other sites More sharing options...
Noise Posted June 8, 2005 Share Posted June 8, 2005 I have to agree, this is great stuff... Hell, why did I ever bother taking that vbs scripting class, I still use batch files /runs off to check Martin's blog... 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