Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use arrays in BAT batch processing

Shulou Source: shulou.com Published: 2022-06-03 19:49:20 11月12日 Update

This article mainly introduces how to use arrays in BAT batch processing, which is very detailed and has a certain reference value. Friends who are interested must read it!

There is no native support for arrays in batch instructions, but that doesn't mean it can't be simulated.

Take a look at the following code:

SET Obj_Length=2 SET Obj [0] .name = Test1SET Obj [0] .value = Hello World SET Obj [1] .name = Test2SET Obj [1] .value = blahblah

This defines an array, and it is an array of structures.

When you need a value, you can play like this:

SET Obj_Index=0: LoopStartIF% Obj_Index% EQU% Obj_Length% GOTO: EOF SET Obj_Current.Name=0SET Obj_Current.Value=0 FOR / F "usebackq delims==. tokens=1-3"% I IN (`SET Obj [% Obj_Index%] `) DO (SET Obj_Current.%%J=%%K) ECHO Name=% Obj_Current.Name%ECHO Value=% Obj_Current.Value%ECHO. SET / An Obj_Index=%Obj_Index% + 1 GOTO LoopStart

Output result:

Name = Test1Value = Hello WorldName = Test2Value = blahblah above is all the content of the article "how to use arrays in BAT batches". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Array content article this no code representative value interest partner instruction time more knowledge structure result industry information information channel face-to-face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Microsoft MariaDB Apple