我正在编写一个脚本来满足以下条件:
我有输入文件,搜索目录是常量,文件名格式也是常量。
我使用了以下脚本:
@ECHO OFF
FOR /f "tokens=2 delims=," %%b IN (test.txt) DO^
( dir *%b%*.log IN "D:\test" if
(*%b%*.log = "" echo "file not found" )
Else DO xcopy "D:\test\"*%b%*.log C:\dest )
但是,我无法运行代码。 请帮忙。
答案 0 :(得分:0)
还有点不清楚,也许这有效:
@ECHO OFF
FOR /f "tokens=2 delims=," %%b IN (test.txt
) DO If not exist "D:\test\*%%b*.log" (
echo "file "D:\test\*%%b*.log" not found"
) Else (
xcopy "D:\test\*%%b*.log" C:\dest
)
答案 1 :(得分:0)
以下是帮助您的示例:
@Echo Off
Set "InFile=test.txt"
Set "ChkDir=D:\test"
Set "SavDir=C:\dest"
If Not Exist "%ChkDir%\" GoTo :EOF
If /I Not "%CD%"=="%SavDir%" (CD /D "%SavDir%" 2>Nul||GoTo :EOF)
For /F "UseBackQ Tokens=2 Delims=," %%A In ("%InFile%"
) Do If Exist "%ChkDir%\*%%~A*.log" (Copy /Y "%ChkDir%\*%%~A*.log">Nul 2>&1
) Else Echo "%ChkDir%\*%%~A*.log not found"
Pause