Question Locked

Batch File Scripting to Check for Multiple Files

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi - just looking for some guidance here... I need to know how to have a batch file look for the presence of multiple files before it processes. I understand that IF EXIST might work for this, but for multiple files - I am not sure.

Example: User executes Script.bat that looks something like the following:

@echo off
echo.
echo Processing...
echo.
cd C:\BIN
program.exe *.pri > Output.txt
exit
---

The problem is that if there are two files with .pri extensions in the folder, the program will take a lot longer to output to a text file. So the logic being that, if more than 1 .pri file exists, display a message stating "Multiple files detected. The output might take some time...Continue Processing?"

Ideally, the user should only be working with one file at a time and should not be processing multiple files.

If this cannot be done through a batch, that is understandable. If there might be a viable solution using VB instead, I'm game. Any help would be greatly appreciated. Hope this post makes sense!

3 replies

by bizzo

The following will count the number of *.pri files in the current directory:

-------------------------------
set numpri=0
for %%I in (*.pri) do (
set /a numpri += 1
)
if %numpri% GTR 1 echo Multiple files detected. The output might take some time...Continue Processing?

---------------------------------------

This discussion is closed to new replies.