WatchDirectory Forum
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl
watchDirectory forums >> How to... >> Count the files
http://www.watchdirectory.net/cgi-bin/yabb25/YaBB.pl?num=1133985298

Message started by sjdubois on Dec 7th, 2005 at 8:54pm

Title: Count the files
Post by sjdubois on Dec 7th, 2005 at 8:54pm
I have an Application which needs ten files before it starts processing. The files come from different systems but all end up in the same directory. What is the best way to insure all ten files have arrived before kicking off the batch job.

Thanks

S

Title: Re: Count the files
Post by Gert on Dec 7th, 2005 at 9:19pm
Hi "S",

Easiest would be if the 10th file has a special name, for example "thelastfile.txt".
In that case you can use the files that trigger events tab to only start when *\thelastfile.txt" is created.

If that's not possible, because you don't know the name of the last file, we need to count the files before starting your program.

Use the batch file plugin to start the following .bat file
[code]
SET COUNT_FILES_DIR=%WD_DIR%
Call :CountFiles
IF %COUNTED_FILES% LSS 10 GOTO :EOF

"C:\Program Files\MyApp\My Application.exe"
GOTO :EOF


:CountFiles
rem
rem count all files inside the monitored directory
rem Input:  COUNT_FILES_DIR - the directory for which we count files
rem Output: COUNTED_FILES - number of files
rem
SET COUNTED_FILES=0
FOR %%C IN ("%COUNT_FILES_DIR%\*.*") DO (
     Call :CountFilesAddOne
)
GOTO :EOF

:CountFilesAddOne
SET /a COUNTED_FILES=%COUNTED_FILES% + 1
GOTO :EOF


[/code]

That should do the trick!

Gert

Title: Re: Count the files
Post by sjdubois on Dec 7th, 2005 at 9:25pm
Thanks for the quick turnaroud Gert!!!

I will download the application and test it. If everything checks out I will be a paying customer very soon.

Best Wishes

S

Title: Re: Count the files
Post by Gert on Dec 7th, 2005 at 9:27pm
I've changed the script a bit (some errors removed, mostly naming), so be sure to use the current version.

oooh, not tested...

Gert

WatchDirectory Forum » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2017. All Rights Reserved.