我正在尝试将文件的内容设置为我的变量'reportPath'。变量'latestReport'保存文件的路径。当我运行此命令时
for /F %%z in (%latestReport%) do set "reportPath=%%z"
我收到此问题标题中提到的错误(“系统无法找到文件”)。但是,如果我将%latestReport%替换为文件的路径,则代码将完美执行。
如何让代码读取我的%latestReport%变量作为文件名?
以下是整个脚本:
@echo off
setLocal Enabledelayedexpansion
set "subject="
set "reportPath="
if "%1"=="" (
for /F "delims== tokens=2" %%a in ('findstr /B test_report_directory my_file_here.properties') do set testReportDir=%%a
set "subject=RentalMan Test Execution Results"
goto :runemaildriver
)
set testReportDir=%~f1
if not exist %testReportDir% (
:: finds string test_report_directory in config file
for /F "delims== tokens=2" %%a in ('findstr /B test_report_directory my_file_here.properties') do set "testReportDir=%%a"
) else (
shift
)
if "%1"=="" (
set "subject=RentalMan Test Execution Results"
) else (
for %%a in (%*) do (
if not exist %%a (
set "subject=!subject!%%a "
)
)
set "subject=!subject:~0,-1!"
)
:runemaildriver
echo testReportDir: %testReportDir%
set latestReport=%testReportDir%\currrentReportPath.txt
echo latestReport: %latestReport%
for /F %%z in (%latestReport%) do set "reportPath=%%z"
echo reportPath: %reportPath%
for /F "delims=: tokens=2" %%d in ('findstr \B Environment %reportPath%') do set "env=%%d"
echo env: %env%
echo Emailing latest TestReport in %testReportDir% with subject line "%subject%"...