I have a Windows batch script which uses if exist, (I replaced long pathnames with SomePath):
if exist "D:\SomePath\Blah\Inbox\*.*" CALL :SUB_MoveFiles Blah
The Inbox directory, in this example, has two subdirectories, Archive and Work.
If the Inbox directory contains files, the if exist succeeds, and the subroutine is called, (where all the files in the Inbox are processed).
If the Inbox directory contains only subdirectories, the if exist also succeeds, (ERRORLEVEL is 0), and the subroutine is called. However it fails miserably because there are no files to process.
I've looked at, (but not yet tried), the for /f command, but havent thought of a way to make it work.
The SUB_Movefiles subroutine is designed to work on all the files in the Inbox at once, (that is, it does not traverse subdirectories).
I am looking for a way to have the If Exist command only succeed if there are files in the Inbox. Alternatively, a way to make the pattern *.* work as I expect, (i.e. *.* should not match the subdirectories, only files with names including a period).
Here is the subroutine, (most of it anyway).
:SUB_MoveFiles
REM Archive inbound files
REM Combine multiple files into one file
REM Copy to EDI Inbound
REM Archive combined file
echo ERRORLEVEL is %ERRORLEVEL%
echo ===== Processing Trading Partner %1 ===== >> %LogFile%
MOVE "D:\SomePath\%1\Inbox\*.*" "D:\SomePath\%1\Inbox\work\"
copy "D:\SomePath\%1\Inbox\work\*.*" "D:\SomePath\%1\Inbox\work\%1_Inbound_%d%_%t%.edi"
rem Finish Archiving
echo ===== Archiving Trading Partner %1 ===== >> %LogFile%
copy "D:\SomePath\%1\Inbox\work\%1_Inbound*.edi" "D:\SomePath\EDI\edidata\inbound\"
echo copy "D:\SomePath\%1\Inbox\work\%1_Inbound*.edi" "\\Server\C$\CommonReceive"
move "D:\SomePath\%1\Inbox\work\*.*" "D:\SomePath\%1\Inbox\archive\"
echo.
exit /B