I am new to Batch coding. So struggling with basics. I want to concatenate 2 variables and then print its concatenated result in the third variable.
Batch code
@echo off
SET basePath = C:\Users\Documents\
echo basePath - %basePath%
SET fileName = T_test
echo fileName - %fileName%
SET extension= .csv
echo extension - %extension%
SET finalvalue = %basePath%%fileName%%extension%
echo finalvalue - %finalvalue%
pause
Actual Output
basePath -
fileName -
extension - .csv
finalvalue -
Expected Output
basePath - C:\Users\Documents\
fileName - T_test
extension - .csv
finalvalue - C:\Users\Documents\T_test.csv
*****Update******
Since the fileName variable has multiple values separated by a comma. I want to iterate it one-by-one
Batch Code
@echo off
SET basePath=C:\Users\Documents\
echo basePath - %basePath%
SET fileName=T_test,T_test2,T_test3
echo fileName - %fileName%
SET extension=.csv
echo extension - %extension%
for %%f in (%fileName%) do (
SET completepath=%basePath%%%f%extension%
echo completepath - %completepath%
)
pause
Actual Output
basePath - C:\Users\Documents\
fileName - T_test,T_test2,T_test3
extension - .csv
completepath -
completepath -
completepath -
Expected Output
basePath - C:\Users\Documents\
fileName - T_test,T_test2,T_test3
extension - .csv
completepath - C:\Users\Documents\T_test.csv
completepath - C:\Users\Documents\T_test2.csv
completepath - C:\Users\Documents\T_test3.csv
Code Update 2:
@echo off
setlocal EnableDelayedExpansion
SET basePath=C:\Users\Documents\
echo basePath - %basePath%
SET fileName=T_test,T_test2,T_test3
echo fileName - %fileName%
SET extension=.csv
echo extension - %extension%
for %%f in (%fileName%) do (
:: below echo prints expected value i.e. 1st iteration - T_Test, 2nd iteration - T_test2, 3rd iteration - T_test3
echo current file name - %%f
SET completepath=%basePath%!f!%extension%
:: below echo prints nothing, expected value 1st iteration - C:\Users\Documents\T_test.csv, 2nd iteration - C:\Users\Documents\T_test2.csv
echo completepath - %completepath%
)
pause