#echo off
for /f "tokens=1,2 delims=," %%x in (my.csv) do (
if %M% LSS %%x set M=%%x
)
echo Max X Value= %M%
Sometimes it works fine, sometimes it fails with following error:
%x was unexpected at this time.
The problem is that you're using %m% inside a for loop. This is evaluated when the loop is read (before any iterations at all). In other words, the entire loop, up to and including the closing parenthesis, is read and evaluated before executing. So %m% will always be it's initial value no matter what you actually set it to within the loop.
An example should hopefully illustrate this:
set val=7
for %%i in (1) do (
set val=99
echo %val%
)
echo %val%
which results in the unexpected (to some):
7
99
simply because the %val% in the first echo statement is interpreted (i.e., the entire for loop is interpreted) before any of it is run.
You need delayed expansion along with something that will force the value of m to be set to the first %%x regardless. Using the setlocal command and !m! instead of %m% will delay evaluation of m until each time the line is executed.
In addition, setting m initially to nothing and forcing it to be %%x when it is nothing will ensure the first value of %%x is loaded into m.
#echo off
setlocal enableextensions enabledelayedexpansion
set m=
for /f "tokens=1,2 delims=," %%x in (my.csv) do (
if "!m!" == "" set m=%%x
if !m! lss %%x set m=%%x
)
echo Max X Value = !m!
endlocal
Using the above code with this my.csv file:
1,a
2,b
10,c
3,d
results in the output of:
Max X Value = 10
as expected or, for your sample data in another comment:
422,34
464,55
455,65
421,88
you get:
Max X Value = 464
There's no environment variable named M set, so when this line is interpreted:
if %M% LSS %%x set M=%%x
After the 1st round of replacements, it looks to the interpreter something like
if LSS %x set M=%x
To avoid the problems that paxdiablo mentions about %M%being expanded only when the loop is first you can use the delayed expansion feature that he discusses, or move testing and setting M to a subroutine that is called from the loop but exists outside the loop so it gets interpreted (and expanded) on each call:
#echo off
set M=
for /f "tokens=1,2 delims=," %%x in (my.csv) do (
call :setmax %%x
)
echo Max X Value= %M%
goto :eof
:setmax
if "%M%" == "" set M=%1
if %M% LSS %1 set M=%1
goto :eof
The problem is in your if %M% statement. Where is %M% ? declare it first eg
#echo off
set M=""
for /f "tokens=1,2 delims=," %%x in (file) do (
if %M% LSS %%x set M=%%x
)
echo Max X Value= %M%
Alternative, you can use vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
t=0
Do Until objFile.AtEndOfStream
linenum = objFile.Line
strLine = objFile.ReadLine
s = Split(strLine,",")
For Each num In s
WScript.Echo "num "&num
If Int(num) >= t Then
t=Int(num)
End If
Next
WScript.Echo "Max for line:" & linenum & " is " & t
Loop
example output
C:\test>type file
422,34464,55455,65421,88
C:\test>cscript //nologo test.vbs file
Max for line:1 is 65421
UPDATE: To find max value column wise
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
t=0
Do Until objFile.AtEndOfStream
linenum = objFile.Line
strLine = objFile.ReadLine
s = Split(strLine,",")
If Int(s(0)) >= t then
t=Int(s(0))
End If
Loop
WScript.Echo "Max is " & t & " (line: " & linenum & ")"
output
C:\test>type file
422,34
464,55
455,65
421,88
C:\test>cscript //nologo test.vbs file
Max is 464 (line: 2)
Related
This might be an XY question, but I am trying to echo various lines from a text file.
#setlocal enableextensions enabledelayedexpansion
#echo off
set /a "line = 0"
for /f "tokens=* delims= " %%a in (file.txt) do (
set /a "line = line+1"
if !line!==18 set thing1=%%a
if !line!==19 set thing2=%%a
if !line!==20 set thing3=%%a
)
endlocal & set thing1=%thing1% & set thing2=%thing2% & set thing3=%thing3%
echo:
echo %thing1%
echo %thing2%
echo %thing3%
pause
This works well and is neat compared to others I found so I was tiring to to make it more adaptable. I can make the line numbers variable, but what if I wanted four lines, or a range of lines? So I tried to make a for loop.
List all the lines:
(
echo #setlocal enableextensions enabledelayedexpansion
echo #echo off
echo set /a "line = 0"
echo for /f "tokens=* delims= " %%a in (file.txt^) do (
echo set /a "line = line+1"
)>>test.bat
for /l %%m in (1,1,10) do (
echo if !line!==%%m set thing%%m=%%%%a
)>>test.bat
echo )>>test.bat
echo endlocal ^& )>>test.bat
for /l %%m in (1,1,10) do (
echo set thing%%m^=%%thing%%%%m ^&
)>>test.bat
Then I could echo %thing(anynumber%) as I wished.
This runs into problems when the for loop list need to be on the same line:
endlocal & set thing1=%thing1% & set thing2=%thing2% & set thing3=%thing3%
Instead it outputs:
endlocal &
set thing1=%thing%1 &
set thing2=%thing%2 &
set thing3=%thing%3 &
etc...
I know prompt $H can backspace, but I think that is a dead end for what I am trying here. I can't find much on reverse line feed online. Also it adds an ampersand to the final %%thing%% in the list.
Sample file.txt
This is line one
This is line two
This is line three
This is line four
This is line five
This is line six
This is line seven
This is line eight
This is line nine
This is line ten
Maybe findstr is the way to go about this. I found this and edited it to suit what I was trying to do:
:start
cls
set /p "line= Which lines?"
for /f "tokens=* delims=[] " %%a in ('type file.txt^|find /v /n ""') do (
echo/%%a|findstr /l /b "%line%" >nul && echo/%%a
)
pause
goto :start
But with an input of 1 it will echo every instance beginning with "1" i.e. 1,11,12,13 etc. This seems to be nearly there. I've tried various switches from the findstr /?, but can't figure it out. If it could do input ranges too, so input line 1-5,7,12-15 would echo them 10 lines.
This should do (although not with ranges):
#echo off
setlocal
set lines=1,5,6,8
(for %%a in (%lines%) do echo %%a:)>lines.txt
for /f "tokens=1,* delims=:" %%a in ('type file.txt^|findstr /n "^"^|findstr /bg:lines.txt') do echo/%%b
del lines.txt
The first for loop builds a temporary file for findstr /g (see findstr /? for details).
The second one adds line numbers, looks them up in the file and prints the original line if the line number is in the file.
The numbers in %lines% can be delimited by any standard delimiters (TABs, SPACEs, Commas and even = (not recommended - stay with spaces and/or commas)
To expand to Ranges 5-10, you'd need to parse %lines% with some more code (hard to make that fool-proof) and "translate" to single line numbers to write into lines.txt
(We could also expand %lines% to a REGEX search string or findstr, avoiding a temporary file, but it's much easier to understand and maintain this way)
Edit: implemented a simple "range extension" (without checking for plausability):
#echo off
setlocal
set "lines=1,4-6,9"
(for %%a in (%lines%) do (
echo %%a|find "-" >nul && call :range %%a || echo/%%a:
))>lines.txt
echo lines %lines% are:
for /f "tokens=1,* delims=:" %%a in ('type file.txt^|findstr /n "^"^|findstr /bg:lines.txt') do echo/%%b
del lines.txt
goto :eof
:range
for /f "tokens=1,2 delims=-" %%b in ("%1") do (
for /l %%i in (%%b,1,%%c) do echo %%i:
)
goto :eof
Output (with your sample input file):
lines 1,4-6,9 are:
This is line one
This is line four
This is line five
This is line six
This is line nine
PS: this outputs the lines in their original order (set "lines=1,4-6,8" and set "lines=8 1 4-6" give the same output (due to how findstr /g works))
I am not really understanding the arrays. I will have another look next week. So far I've got this based on #Stephan answer.
choice /c rs /m "RANGE MODE OR SPECIFIED MODE"
goto:%errorlevel%
:2
:specified
echo:
set /p lines=ENTER SPECIFIC LINES (seperated by spaces)?
(for %%a in (%lines%) do echo %%a:)>lines.txt
for /f "tokens=1,* delims=:" %%a in (
'type file.txt^|findstr /n "^"^|findstr /bg:lines.txt'
) do (
echo/%%b)
del lines.txt
pause
goto :eof
:1
:range
echo:
set /p ran=ENTER RANGE (e.g. 15-25)?
echo %ran%>range.txt
for /f "tokens=1,* delims=-" %%a in (range.txt) do (
set line1=%%a
set line2=%%b)
del range.txt
(for /l %%a in (%line1%,1,%line2%) do echo %%a:)>lines.txt
for /f "tokens=1,* delims=:" %%a in (
'type file.txt^|findstr /n "^"^|findstr /bg:lines.txt'
) do (
echo/%%b)
del lines.txt
pause
goto :eof
Trying to follow arrays through this link I can see when setting elements within the batch but not pointing file.txt. I tried
for /f %%a in ('type file.txt^|echo !elem[%2%]!') do echo %%a
and
for /f "tokens=* delims=" %%a in ('type file.txt^|find /v /n ""') do (
echo/%%a|findstr /l /b "!elem[%2%]!" >nul && echo echo/%%a)
Anyway that is a different question, I have work through that link next week.
Cuts the number of lines from the top or bottom of file.
This is similar to Unix's Tail command of which there is no Windows' equivalent.
To use
Cut
cut {t|b} {i|x} NumOfLines
Cuts the number of lines from the top or bottom of file.
t - top of the file
b - bottom of the file
i - include n lines
x - exclude n lines
Example
cscript //nologo c:\folder\cut t i 5 < "%systemroot%\win.ini"
Copy following lines into cut.vbs
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set rs = CreateObject("ADODB.Recordset")
With rs
.Fields.Append "LineNumber", 4
.Fields.Append "Txt", 201, 5000
.Open
LineCount = 0
Do Until Inp.AtEndOfStream
LineCount = LineCount + 1
.AddNew
.Fields("LineNumber").value = LineCount
.Fields("Txt").value = Inp.readline
.UpDate
Loop
.Sort = "LineNumber ASC"
If LCase(Arg(1)) = "t" then
If LCase(Arg(2)) = "i" then
.filter = "LineNumber < " & LCase(Arg(3)) + 1
ElseIf LCase(Arg(2)) = "x" then
.filter = "LineNumber > " & LCase(Arg(3))
End If
ElseIf LCase(Arg(1)) = "b" then
If LCase(Arg(2)) = "i" then
.filter = "LineNumber > " & LineCount - LCase(Arg(3))
ElseIf LCase(Arg(2)) = "x" then
.filter = "LineNumber < " & LineCount - LCase(Arg(3)) + 1
End If
End If
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
For a line count program
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Do Until Inp.AtEndOfStream
Line=Inp.readline
Count = Count +1
Loop
outp.writeline Count
I have no idea how to get what described here using an Win CMD batch script:
pseudo-code
set aPath=C:\just\a\long\path\to\a\file\in\the\file\system
set aDir=file
... some logic here
echo %result%
Should print
C:\just\a\long\path\to\a\file
It should stop at the first occurrence found, but it would be nice to specify also the occurence (optional).
ONLY Windows CMD SOLUTIONS ARE WELCOME no Powershell code nor external tools, please. I'm looking for a pure Windows CMD solution.
I'm not quite sure to what you refer with occurence
Using a shuffle approach and self modifying code to get the dir levels
:: Q:\Test\2019\08\29\SO_57717256.cmd
#Echo off & Setlocal EnableDelayedExpansion
set "aPath=C:\just\a\long\path\to\a\file\in\the\file\system"
set "aDir=file"
echo aPath = %aPath%
echo aDir = %aDir%
::... some logic here
set "intermediate=!apath:*%aDir%=!"
set "result=!aPath:%intermediate%=!"
:: and some vodoo there ;-)
Set i=0
Set "aPath=%aPath:\="&Set /a i+=1&Set "aPath[!i!]=%"
echo result= %result%
for /l %%L in (1,1,%i%) Do if "%aDir%"=="!aPath[%%L]!" (
echo aPath[%%L] = !aPath[%%L]! ^<^<^< matches aDir %aDir%
) else (
echo aPath[%%L] = !aPath[%%L]!
)
Sample output:
> Q:\Test\2019\08\29\SO_57717256.cmd
aPath = C:\just\a\long\path\to\a\file\in\the\file\system
aDir = file
result= C:\just\a\long\path\to\a\file
aPath[1] = just
aPath[2] = a
aPath[3] = long
aPath[4] = path
aPath[5] = to
aPath[6] = a
aPath[7] = file <<< matches aDir file
aPath[8] = in
aPath[9] = the
aPath[10] = file <<< matches aDir file
aPath[11] = system
Here is a little approach using a recursive sub-routine, just for fun:
#echo off
set "aPath=C:\just\a\long\path\to\a\file\in\the\file\system"
set "aDir=file"
set "result=" & set "found="
call :RECURSIVE "%aPath%\."
if defined found echo/%result%
exit /B
:RECURSIVE
if "%~nx1" == "" set "result=%~dp1" & exit /B
call :RECURSIVE "%~dp1."
if defined found (exit /B) else set "result=%result%%~nx1\"
if /I "%~nx1" == "%aDir%" set "found=#" & set "result=%result:~,-1%"
This makes use of the ~ modifiers of command line or sub-routine arguments (parameters), which allow to split a path into pieces.
A simpler approach:
#echo off
setlocal EnableDelayedExpansion
set aPath=C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file\folder
set aDir=file
echo %aPath%
rem This FOR is just for testing; remove it...
for /L %%n in (1,1,3) do (
set "n=%%n"
set "result="
for %%a in ("!aPath:\%aDir%\=" "!") do if !n! gtr 0 set "result=!result!%%~a\%aDir%\" & set /A n-=1
echo %%n: !result:~0,-1!
)
Output example:
C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file\folder
1: C:\just\a\long\path\to\a\file
2: C:\just\a\long\path\to\a\file\in\the\file
3: C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file
EDIT: An even simpler method with the aid of some magic:
#echo off
setlocal EnableDelayedExpansion
set aPath=C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file\folder
set aDir=file
echo %aPath%
set n=%1
set "result="
set "p=%aPath:\=" & (if !n! gtr 0 set "result=!result!\!p!") & (if "!p!" equ "!aDir!" set /A n-=1) & set "p=%"
echo %1: %result:~1%
Output example:
C:\Tests> test 1
C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file\folder
1: C:\just\a\long\path\to\a\file
C:\Tests> test 2
C:\just\a\long\path\to\a\file\in\the\file\system\filenot\file\folder
2: C:\just\a\long\path\to\a\file\in\the\file
How do I set my if statement to call on different predefined variables based on user input.
Example 1 is red 2 is orange 3 is blue 4 is random.
If user puts 1 they get red. If they put 2 they get orange. If they put 3 they get blue. If they put 4 they get either red, orange, or blue.
The following script shows one way of doing it, using arrays of colors and a method for doing double expansion on a variable (allowing for array access):
#setlocal enableextensions enabledelayedexpansion
#echo off
set color[1]=red
set color[2]=orange
set color[3]=blue
:loop
set /p inp="Enter a number [1=red, 2=orange, 3=blue, 4=random]: "
if "%inp%"=="4" set /a "inp = %RANDOM% %% 3 + 1"
call set color=%%color[%inp%]%%
if "%color%"=="" goto loop
endlocal && set color=%color%
For a more generalised solution, you can look at the following script, which better handles the prompting for arbitrary colors:
#setlocal enableextensions enabledelayedexpansion
#echo off
rem Clear out all color variables then create array.
set color=junk
for /f "delims==" %%a in ('set color') do set %%a=
set /a "count = 0"
set /a "count = count + 1" && set color[!count!]=red
set /a "count = count + 1" && set color[!count!]=orange
set /a "count = count + 1" && set color[!count!]=blue
set /a "count = count + 1" && set color[!count!]=green
set /a "next = count + 1"
rem Loop until color is valid.
:loop
echo.Choices:
for /l %%a in (1,1,%count%) do (
set value=!color[%%a]!
echo. %%a. !value!
)
echo. %next%. Random choice from above
set /p inp="Enter a number: "
rem set inp=1
rem Special handling, choose random value
if "%inp%"=="%next%" set /a "inp = %RANDOM% %% count + 1"
call set color=%%color[%inp%]%%
if "%color%"=="" goto loop
rem Exit local scope, "leaking" color value.
endlocal && set color=%color%
#ECHO Off
SETLOCAL
SET "choices=1=red 2=blue 3=green 4=random"
SET /p inp="[%choices%]: "
FOR /f %%a IN ('echo %choices: =^&echo %') DO SET /a maxchoice=%%a
IF "%inp%"=="%maxchoice%" SET /a inp=%RANDOM% %% (maxchoice - 1) +1
FOR /f "tokens=1,2" %%a IN ('echo %choices: =^&echo %') DO IF "%%a"=="%inp%" SET "hue=%%b"
ECHO %hue%
GOTO :EOF
Here's my version. All you need to do is follow the bouncing ball setting up choices and ensure that random is the last selection.
I started to write a comment as reply to new paxdiablo's solution, but it becomes too large, so I prefer to write my own solution here with all those points included:
#echo off
setlocal EnableDelayedExpansion
rem Create the color array
set n=0
for %%a in (red orange blue green) do (
set /A n+=1
set color[!n!]=%%a
)
set /A next=n+1
rem Show the available colors menu
echo Choices:
echo/
for /L %%i in (1,1,%n%) do echo %%i. !color[%%i]!
echo %next%. Random choice from above
echo/
rem Loop until color is valid
:loop
set /P "inp=Enter a number: "
if "%inp%" equ "%next%" set /A inp=%random% %% n + 1
set color=!color[%inp%]!
if "%color%" equ "" goto loop
echo/
echo Color: %color%
I'm attempting to rewrite an .sh script to a .bat file so that I can test it on Windows VM.
I have encountered an issue with FOR /F loop, I am unable to use the variables I set in the loop, I'm really frustrated about this. I have been looking around for a while and I have enabled delayed expansion, to no luck. Below is the piece of code :
setlocal ENABLEDELAYEDEXPANSION
FOR /F "eol=; tokens=1,2,3,4,5,6,7,8,9,10 delims=, " %%i in (%SOutPath%) do (
SET sKic1Length = 20
SET sRAMTar = %%i
SET admCode = %%j
SET pin1Code = %%k
SET pin2Code = %%l
SET sKic1 = %%m
SET sKic1Length = %%n
SET sKid1 = %%o
SET sKid1Length = %%p
SET sRAMMSL=%%r
IF sKic1Length EQU 16 SET sKic1Length=11
IF sKic1Length EQU 32 SET sKic1Length=15
IF sKic1Length EQU 48 SET sKic1Length=19
::This echo outputs 'Echo is off' so variable is empty
#echo %sKic1Length%
)
::Also returns same
ECHO %sKid1Length%
Below is the file that I'm reading in the loop :
; ;, RAMTAR, ADM1, PIN1, PIN2, KIC1, KICLENGTH,KID1, KIDLENGTH, RAMMSL
000000, 17182320, 2387, 1116, 607038CA34A91FB1, 16, 607038CA34A91FB, 16, 0200
I would appreciate any input.
Thank you
You have to use ! instead of % on ENABLEDELAYEDEXPANSION in a loop
#echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "eol=; tokens=1,2,3,4,5,6,7,8,9,10 delims=, " %%i in (%SOutPath%) do (
set "sKic1Length=20"
set "sRAMTar=%%i"
set "admCode=%%j"
set "pin1Code=%%k"
set "pin2Code=%%l"
set "sKic1=%%m"
set "sKic1Length=%%n"
set "sKid1=%%o"
set "sKid1Length=%%p"
set "sRAMMSL=%%r"
if "!sKic1Length!" equ "16" set "sKic1Length=11"
if "!sKic1Length!" equ "32" set "sKic1Length=15"
if "!sKic1Length!" equ "48" set "sKic1Length=19"
echo.!sKic1Length!
)
echo.%sKid1Length%
endlocal
If the last echo returns nothing, then I assume, that in the last iteration %%p was empty.
There are two files which get uploded in D:\CW-Data\edw location every day between 1am to 1:15 am.
My requirement is to auto send us the email wih the file name when both the files are received.
I tried writing a cript which troughs the lastfile which arrives, but i am not getting the expected result. Please help me out:
My script was
set srcDir=D:\Mitul\Quantum AWR Report_23Apr_3am_2pm
set lastmod=
pushd %srcDir%
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
echo %lastmod%
This is a general purpose script for sending an email.
Original thread at https://groups.google.com/forum/?fromgroups=#!msg/alt.msdos.batch.nt/l_8K11YzS0A/WfbVBoJe-l8J
:: Allows ssl and port 465
:: email.cmd ::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Tom Lavedas, Mod 2.14 to eliminate temporary VBS script file
:: Works with IE5+ (and maybe earlier versions as well)
#echo off
setlocal
:Use command line arguments, if supplied
if [%1] EQU [] goto :Continue
set "Arg=%1"
set "Arg=%Arg::==%"
set "Arg=%Arg:/=%"
set "%Arg%"
shift
goto :Use
:Continue
:: defaults
if not defined From set "From=userid#gmail.com"
if not defined To set "To=you#somemail.com"
if not defined Subj set Subj="email test %date% %time%"
if not defined Body set Body="Did it work? %date% %time%"
if not defined Serv set "Serv=smtp.gmail.com"
if not defined Auth set "Auth=userid#gmail.com"
if not defined Pass set "Pass=password"
if not defined fileattach set "fileattach="
if not defined Port set "Port=465"
if not defined SSL set "SSL=True"
if not defined Timeout set "Timeout=25"
call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass% %fileattach%
if %errorlevel% NEQ 0 echo Error: %ErrorLevel%
if %0==%~f0 pause
exit /b %ErrorLevel%
:send
set "cdoSchema=http://schemas.microsoft.com/cdo/configuration"
set arguments="%~1+%~2+%~3+%~4+%~5+%~6+%~7+%~f8"
set VBS=resizeTo 1,1:moveTo 1, 3000:
set VBS=%VBS%set ws=createobject("wscript.shell"):
set VBS=%VBS%with createobject("scripting.filesystemobject")
set VBS=%VBS%Execute ws.ExpandEnvironmentStrings(
set VBS=%VBS%.GetStandardStream(0).readALL):end with:
set "VBS=about:<script type=text/vbs>%VBS%:close</script>"
set "Match=VBScript start"
for /f "delims=[]" %%N in (
'find /n "### %Match% ###" ^<"%~f0"'
) do set "N=%%N"
for /f "tokens=1,2 delims=#" %%A in (
'more +%N% "%~f0" ^| mshta.exe "%VBS%"'
) do #echo %%B & exit /b %%A
exit /b 1 % Error in previous statement %
' ### VBScript start ###
set StdOut=.GetStandardStream(1)
args = Split(%arguments%, "+")
with CreateObject("CDO.Message")
.From = args(0)
.To = args(1)
.Subject = args(2)
.Textbody = args(3)
if args(7) <> "" then .AddAttachment args(7)
with .Configuration.Fields
.Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
.Item ("%cdoSchema%/smtpserver") = args(4)
.Item ("%cdoSchema%/smtpserverport") = %Port%
.Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
.Item ("%cdoSchema%/sendusername") = args(5)
.Item ("%cdoSchema%/sendpassword") = args(6)
.Item ("%cdoSchema%/smtpusessl") = %SSL%
.Item ("%cdoSchema%/smtpconnectiontimeout") = %Timeout%
.Update
end with ' Configuration.Fields
On Error Resume Next
.Send
end with ' CDO.Message
if Err.Number = 0 then
sRes = "0#Mail sent without error"
else
sRes = Hex(Err.Number) + "#" + Err.Description
end if
stdout.writeline sRes
' ### VBScript end ### - Must be the end of the batch file
#echo off
setlocal
set srcDir=D:\CW-Data\edw
set file1=whateverthenameofthefirstfileis
set file2=whateverthenameofthesecondfileis
:loop
set /a count=0
for /f %%a in ('dir /b "%srcdir%\%file1%" "%srcdir%\%file2%" 2^>NUL') do set /a count+=1
IF NOT %count%==2 timeout /t 5 >nul&GOTO loop
echo send the email
This will wait for the two files to arrive. If either is missing, timeout 5 seconds and try again.
Don't have enough details to provide more.
Addendum:
If your edition of windows doesn't include timeout, try
IF NOT %count%==2 ping -n 5 127.0.0.1 >nul&GOTO loop