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
Check if targetfolder is empty before copying file (Read 1071 times)
Maurice Mullenders
YaBB Newbies
*
Offline



Posts: 3
Netherlands
Check if targetfolder is empty before copying file
Apr 1st, 2016 at 2:18pm
 
Before copying files, the targetfolder must be empty. How can I perform a precheck?
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: Check if targetfolder is empty before copying file
Reply #1 - Apr 2nd, 2016 at 8:12am
 
Hello Maurice,

Should the task wait until the target is empty or should the task not copy the file if the target contains a file?
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
 
Maurice Mullenders
YaBB Newbies
*
Offline



Posts: 3
Netherlands
Re: Check if targetfolder is empty before copying file
Reply #2 - Apr 12th, 2016 at 8:54pm
 
Hi Gert, before copying/moving files to the target folder, there should be a check to verify if the target folder is empty. If not no files should be copied at all.
Kind regards, Maurice
Back to top
 
 
IP Logged
 
Gert
YaBB Administrator
*****
Offline



Posts: 2225
The Netherlands
Re: Check if targetfolder is empty before copying file
Reply #3 - Apr 14th, 2016 at 5:51am
 
Ok, on "Filter Events" you can add a "Filter Script" at the bottom of the window.

Save the script below as C:\Bin\filter_no_files.bat and change the directory name on line 4 to the directory you want to check.

Code:
rem filter script that checks if the target directory is empty
rem if it is NOT empty, the task should not proceed.

SET TARGETDIR=C:\Target\Directory

Call :CountFiles

IF "%RESULT%" EQU "0" GOTO :SayYes
GOTO :SayNo


:CountFiles
SET RESULT=0
for %%a in ("%TARGETDIR%\*.*") do Call :CountFiles_AddOne "%%a"
GOTO :EOF

:CountFiles_AddOne
SET /A RESULT=%RESULT% + 1
GOTO :EOF



:SayYes
rem let the task proceed
ECHO Y > "%WD_FILTERRESULT%"
GOTO :EOF


:SayNo
rem do not let the task proceed
ECHO N > "%WD_FILTERRESULT%"
GOTO :EOF
 


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