我的脚本不支持通配符(IF 函数)!Log.txt 是文件名列表,其中一些应该被复制:(如果排除==文件名复制)其余(否则回显 *.html)
for /f "usebackq delims=" %%a in (./Log.txt) do (
IF /i %excl1%==%%a set copy=1
IF /i %excl2%==%%a set copy=1
IF /i %excl3%==%%a set copy=1
IF defined copy (
echo "%source%\%%a"
echo "%savedir%\%%a"
copy "%source%\%%a" "%savedir%\%%a"
) else (
echo "<p><a href=%savedir%\%%a>%%a</a></p>" >> %htmlfile%)
set copy=
)
解决问题的想法?
答案1
无需改变太多:
@echo off
set "dir=C:\your\directory\Log.txt"
set "htmlfile=C:\your\html\file.txt"
set "source=C:\your\source"
set "savedir=C:\your\saved"
set "excl1=firstexclusion"
set "excl2=secondexclusion"
set "excl3=thirdexclusion"
setlocal enabledelayedexpansion
for /f %%A in (%dir%) do (
set "file=%%A"
IF /i !file! == %excl1% (
set copy=1
echo "%source%\!file!"
echo "%savedir%\!file!"
echo "%source%\!file!" "%savedir%\!file!") ELSE (IF /i !file! == %excl2% (
set copy=1
echo "%source%\!file!"
echo "%savedir%\!file!"
echo "%source%\!file!" "%savedir%\!file!") ELSE (IF /i !file! == %excl3% (
set copy=1
echo "%source%\!file!"
echo "%savedir%\!file!"
echo "%source%\!file!" "%savedir%\!file!"
) ELSE (
echo "<p><a href=%savedir%\!file!>!file!</a></p>" >> %htmlfile%
)))
)
首先,我们将启用延迟扩展,以便在整个循环中将其用作%%A
变量!file!
- 然后只需正确设置IF
/ELSE
格式即可。希望这能满足您的要求。