mercredi 24 août 2016

how to scan a folder and store all file names in a array variable and then loop through the array? batch

I am new to batch and I am trying to do the following:

  • reading or scanning a folder
  • hold all file names in folder in an array variable (need to hold file name with or without extension)
  • loop through that array and create a call to a specific file/bat based on the type of file using an IF or CASE statement condition. example: if the filename has the word person in it, call a specific file/bat.

This is what I have so far:

@echo off

setlocal EnableDelayedExpansion

rem Populate the array with existent files in folder
set i=0
for %%b in (*.*) do (
   set /A   i+=1
   set list[!i!]=%%b

)

set Filesx=%i%

rem Display array elements
for /L %%i in (1,1,%Filesx%) do echo !list[%%i]!

Aucun commentaire:

Enregistrer un commentaire