I’m trying to concatenate file name (fileName) behind a directory path (C:\ExecutionSDKTest_10.2.2\Logs) and before a file extension(.log) in batch, but I think because my fileName contains leading and trailing whitespaces, the cmd.exe does not recognize the concatenated path (logPath). Any ideas?
FOR %%G IN (C:\ExecutionSDKTest_10.2.2\*.properties) DO (
Set fileName= %%~nxG
REM echo !fileName!
REM java -jar Test.jar %%~nxG > Logs\%%~nxG.log
set logPath=%C:\ExecutionSDKTest_10.2.2\Logs\%%!fileName!%%.log%
Echo !logPath!
REM print each line in each of the log files
REM FOR /F "tokens=*" %%g in (!logPath!) DO (
REM echo %%g
REM )
pause
)
Are you sure that your filename has a leading and trailing space? Normally it’s not possible, that a filename ends with a space.
Your variable
filenamehas a leading space because you should avoid spaces when using thesetcommand.Also the creation of the
logPathseems to be wrong.A corrected version could look like