My task is to create a script to copy dated sub folders from within folders to another location. The base folders are named 16 hex characters, each has a folder for the year, inside a folder for the month, and inside that a folder for a date, which contains binary (dump) files I need to copy out. There are about 50 folders with around 5 days across two months that I care about (for now), so I want to capture something like the following: C:\DUMPS\2401010153783FB6\2016\09\29*.*
Rather than doing a ton of copypaste script or manually trying to get all the folders I want (human error prone), I thought I should be able to create a BAT file to loop through an array of folder names and get at the files I care about. I found a very helpful piece in the answer from user DSS at the following: How to loop through array in batch?
My problem is that his example shows how to use CALL ECHO instead of just ECHO, but I want to use the string value as part of a folder name, not just print to the console. Here's the work-in-progress code I've developed:
SET COPYPATH=C:\Dumps
SET DESTPATH=D:\NewDumps
SET FOLDERNAME[0]=2401010153783FB6
SET FOLDERNAME[1]=2401010753BBBBCE
SET "X=1" # array start from index 1
:Looping
IF DEFINED FOLDERNAME[%X%] (
CALL ECHO %%FOLDERNAME[%X%]%% REM Works great, I see the value of FOLDERNAME[0] on console.
SET TEMPVAR= CALL ECHO %%FOLDERNAME[%X%]%% REM No good! Result is CALL ECHO.
SET TEMPVAR= CALL %%FOLDERNAME[%X%]%% REM No good! Result is CALL X.
SET TEMPVAR= %FOLDERNAME[%X%]% REM No good! Result is literal FOLDERNAME[0]; I want the value of FOLDERNAME[0].
IF EXIST %TEMPVAR%\2016\09\28 (
COPY %TEMPVAR%\2016\09\28 %DESTPATH%\%FOLDERNAME[%X%]%%\2016\09\28
)
IF EXIST %COPYPATH%\%FOLDERNAME%\2016\09\29 (
COPY %COPYPATH%\%FOLDERNAME%\2016\09\29 %DESTPATH%\%FOLDERNAME%\2016\09\29
)
IF EXIST %COPYPATH%\%FOLDERNAME%\2016\09\30 (
COPY %COPYPATH%\%FOLDERNAME%\2016\09\30 %DESTPATH%\%FOLDERNAME%\2016\09\30
)
IF EXIST %COPYPATH%\%FOLDERNAME%\2016\10\01 (
COPY %COPYPATH%\%FOLDERNAME%\2016\10\01 %DESTPATH%\%FOLDERNAME%\2016\10\01
)
IF EXIST %COPYPATH%\%FOLDERNAME%\2016\10\02 (
COPY %COPYPATH%\%FOLDERNAME%\2016\10\02 %DESTPATH%\%FOLDERNAME%\2016\10\02
)
SET /A "X+=1"
GOTO :Looping
)
I would be fine with using a temporary variable for either path, or I could use the concatenated %COPYPATH%\%FOLDERNAME% syntax (which worked when I set this up for a one-off test, but now I want to loop it 50 times). Any advice is much appreciated!