I need a batch file that monitors additions to my Downloads folder, but only new additions. Something like this:
:START
NumOldFiles = GetNumberOfFilesOld
Delay_30_Seconds
NumNewFiles = GetNumberOfFilesNew
if(NumFilesOld < NumFilesNew)
run_another_batch_file_I_wrote
goto START
else
goto START
I do not want to count subfolders, just the folders and files in the directory.
I have been looking at this:
dir "C:\folder" /b/a |find /v /c "::"
but I don’t know how to store this value and test it as < or >.
Maybe there is a better way to do this, but I can’t think of one right now. Maybe maintain a list and if the new list has a new file run the batch script, replace the old list with the new list, I’m not really sure how to go about this.
Answer 1:
The following snippet should get you going in the right direction. It uses
dir /bto get a raw list of files and usesfc(file compare) to check for differences between each execution of the check.You could use the Task Scheduler to launch this batch file once every x minutes:
Answer 2:
I have always liked a library of batch functions by Ritchie Lawrence. One of those functions is called
GetDirStats.The
GetDirStatsfunction returns the number of files, subdirectories and total size of a specified directory. Might be handy for future reference. Although it’s only tested on NT4/2000/XP/2003.Just change
compact/stocompactto not scan subfolders.