当我在脚本中启用DelayedExpansion时,它并没有回显出" !"文件名中的字符串。例如:
原始
File01-TEXT!.TXT回应出来 File01-TEXT.TXT
我想这是因为function purchaseOrder($user_email,$product_name,$price)
{
$mail = new PHPMailer;
if (EMAIL_USE_SMTP) {
$mail->IsSMTP();
$mail->SMTPAuth = EMAIL_SMTP_AUTH;
if (defined(EMAIL_SMTP_ENCRYPTION)) {
$mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
}
$mail->Host = EMAIL_SMTP_HOST;
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD;
$mail->Port = EMAIL_SMTP_PORT;
} else {
$mail->IsMail();
}
$mail->From = EMAIL_VERIFICATION_FROM;
$mail->FromName = EMAIL_VERIFICATION_FROM_NAME;
$mail->AddAddress($user_email);
$mail->Subject = PURCHASE_ORDER_SUBJECT;
//$link = INVITE_LINK;
$mail->Body = //here check if working jquery plugin can be sent? so that receiver will be able to see it
if(!$mail->Send()) {
$this->errors[] = MESSAGE_VERIFICATION_MAIL_NOT_SENT . $mail->ErrorInfo;
return false;
} else {
return true;
}
}
,但我无法删除,因为我需要它。
setlocal EnableDelayedExpansion
答案 0 :(得分:3)
根据实际代码,您可以禁用延迟扩展,在需要访问修改内容的位置启用它,然后再次禁用
@echo off
setlocal enableextensions disabledelayedexpansion
cd "C:\Files"
for %%a in (*.txt) do (
set "str=%%a"
rem Option 1
echo file: %%a
setlocal enabledelayedexpansion
echo substring: !str:~0,3!
endlocal
rem Option 2 - capture changed value to use inside non delayed expansion context
setlocal enabledelayedexpansion
for %%b in ("!str:~0,3!") do (
enlocal
echo %%a -- %%~b
)
)