Loop through files in a folder and check if they have different extensions
<p>I have a folder that contains files; each document should have .pdf and .xml format. I need to write a BAT file to run from a scheduled task to verify that both documents exist for each.</p>

<p>My logic is:</p>

<ol>
<li>loop through files in the folder</li>
<li>strip each file to its name without extension</li>
<li>check that same name files exist for both .xml and pdf.</li>
<li>if not mark a flag variable as problem</li>
<li>when done, if the flag variable is marked, send an Email notification</li>
</ol>

<p>I know how to use blat to sending email, but I'm having trouble to execute the loop. I found a way to get path and file name without extension but can't merge them.</p>

<p>I've used batch files a few time, before but I'm far from an expert. What am I missing?</p>

<p>Here's the code I have so far:</p>

<pre><code>set "FolderPath=E:\TestBat\Test\"
echo %FolderPath%

for %%f in (%FolderPath%*) do (
  set /p val=&lt;%%f

For %%A in ("%%f") do (
    Set Folder=%%~dpA
    Set Name=%%~nxA
)
echo Folder is: %Folder%
echo Name is: %Name%
if NOT EXIST %FolderPath%%name%.xml
set flag=MISSING
if NOT EXIST %FolderPath%%name%.pdf
set flag=MISSING
)

echo %Flag%
pause
</code></pre>