Reverse an Array in a Windows Batch File

Filed under: Technology — Tags: , , , , , — Developer42 @ 17:58

The below script demonstrates how to reverse the order of elements in an array in a Windows batch file.

@echo off
echo Script Started
setlocal enableextensions
setlocal enabledelayedexpansion

set arrayTest=("1", "2", "3", "test")

echo.Forward: %arrayTest%
for %%1 in %arrayTest% do (call:outputElement %%1)

call:reverseArray %arrayTest%

echo.Backward: %reverseArray%
for %%1 in %reverseArray% do (call:outputElement %%1)


set reverseArray=
for %%1 in %* do (call:reverseArrayX %%1)
set reverseArray=(%reverseArray%)

if "%reverseArray%"=="" (set reverseArray=%1) else (set reverseArray=%1, %reverseArray%)

echo. – %~1



Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: