WatchDirectory home page
WatchDirectory Startseite (Deutsche Version)
Site WatchDirectory (Français)
  Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
   
  HomeHelpSearchLoginRegister  
 
Page Index Toggle Pages: 1
Count the files (Read 2758 times)
sjdubois
YaBB Newbies
*
Offline



Posts: 2
Count the files
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
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2224
The Netherlands
Re: Count the files
Reply #1 - 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


 



That should do the trick!

Gert
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
sjdubois
YaBB Newbies
*
Offline



Posts: 2
Re: Count the files
Reply #2 - 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
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2224
The Netherlands
Re: Count the files
Reply #3 - 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
Back to top
 

Gert Rijs - gert (at) gdpsoftware (dot) com
Blog: http://blog-en.gdpsoftware.com/
End Alzheimer's: http://www.alz.org&&...
WWW WWW GdPSoftware  
IP Logged
 
Page Index Toggle Pages: 1