I am trying to create a menu that allows the user to drill down into a folder in order to batch copy and sync files. However, I am having a tough time accessing array values at the indices the user inputs. In the for loop they display fine so it looks like they are captured correctly in the array.
But when I try to set them or echo them later I don't get the correct output.
Not sure what I am doing wrong here.
:DirectoryContents
setlocal EnableDelayedExpansion
if exist "\\test\proj\dpa3\EXTERIOR\VCSE DVA Sync\%programNameAndYear%" (
echo The sub-folders in this folder on the share drive are:
echo.
Pushd "\\test\proj\dpa3\EXTERIOR\VCSE DVA Sync\%programNameAndYear%"
REM dir /b /ad
set /a ID=0
for /d %%a in (*) do (
set folderName[%ID%]=%%a
echo (!ID!^) %%folderName[%ID%]%%
set /a ID=ID+1
)
echo.
echo Please, select an assembly
SET /P "selection=Input>"
SET assemblyName=!folderName[%selection%]!
echo assemblyName !assemblyName!
call echo Folder0 !folderName[%0%]!
call echo Folder1 !folderName[%1%]!
call echo Folder2 !folderName[%2%]!
echo test !folderName[%selection%]!
call echo test2 %%folderName[%selection%]%%
pause
echo This folder does not exist on the shared drive
)
endlocal
REM pause
popd
exit /b
Ok so based on feedback i made some updates to the code. I'm confident now that the folder names are being properly stored in the array index. I can easily see this by hard coding the index.
So echo Folder0 !folderName[0]!
returns the name of the first folder etc.
However, after changing
set folderName[%ID%]=%%a
echo (!ID!^) %%folderName[%ID%]%%
to
set folderName[!ID!]=%%a
echo (!ID!^) %folderName[!ID!]%
I get a blank following the index number. Ex. (1)
Also the assemblyName variable isn't being set.
I tried
SET assemblyName=!folderName[%selection%]!
call echo assemblyName !assemblyName!
and
SET assemblyName=%folderName[!selection!]%
call echo assemblyName !assemblyName!
both return blanks.
Ultimately what I am trying to do is use the assemblyName variable in the network path to access the folder.
Pushd "\\test\proj\dpa3\EXTERIOR\VCSE DVA Sync\%programNameAndYear%\!assemblyName!\"