Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

making arrays in batch


Recommended Posts

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=2
echo %arr[%n%]%

but that didnt work. :no:

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


Cmd promt I believe cannot handle arrays VBS does handle arrarys.

Note : Arrays always start at Zero

Example = 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

I do not know about php, but you can use varibles in cmd.

Echo Off && CLS && Mode 55,5 && Color 5e

Set Var1=Hello World

Set Var2=ping -n 3 127.0.0.1

Set Var3=Good Bye

Echo.

echo %Var1%

%Var2%>nul

echo.

echo %Var3%

%Var2%>nul

exit

Link to comment
Share on other sites

for %%G in (%location%\*.txt) do (
set /a count+=1
call :exec1 %%~nG
echo %%~nG
)
goto :continue1

:exec1
echo %count%
set mapArray[%count%]=%1
goto :end

:continue1
:end

this 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

Mine is similar :)

Set strArrayNumber=0

For /f "usebackq" %%i IN (`type test.txt`) DO (
Set strArrayValue=%%i
call:functionArray
)

Goto :EOF

:functionArray
set /a strArrayNumber=%strArrayNumber% + 1
set strArrayName.%strArrayNumber%=%strArrayValue%
Goto :EOF

Link to comment
Share on other sites

  • 2 weeks later...

WOW!!! I just stumbled upon this thread quite accidentally (forgot the original search.. more of a tangent.. funny how the net works like that :) )

:thumbup

@Martin Zugec

Thank you for this snippet:

set /a strArrayNumber=%strArrayNumber% + 1

:thumbup

@someuser77

Thank you for this snippet:

set /a count+=1

I'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 by JoeMSFN
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.


×
×
  • Create New...