我正在尝试在目录路径(C:\ ExecutionSDKTest_10.2.2 \ Logs)后面和文件扩展名(.log)之前连接文件名(fileName),但我认为因为我的fileName包含前导和尾随对于空格,cmd.exe无法识别连接路径(logPath)。有任何想法吗?
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
)
答案 0 :(得分:2)
您确定您的文件名有前导和尾随空格吗?通常情况下,文件名以空格结尾是不可能的。
您的变量filename
具有前导空格,因为在使用set
命令时应避免使用空格。
同样,logPath
的创建似乎也是错误的。
更正的版本可能看起来像
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
)