script to detect changes in a folder

  • Thread starter Thread starter Matt Williamson
  • Start date Start date
M

Matt Williamson

I've been working on a script to detect changes in a folder and process the
files that have changed. For some odd reason that I've yet to determine, I
can't get any program (WMI, WaitDirChg, etc) that polls the system for
directory change information to trigger with a few particular files. So, I
think the next step would be just to test for changes in a directory in a
loop. I've come up with this so far but I'm having trouble figuring out the
best way to verify that the file is finished downloading before processing
it. The obvious way is just start another inner loop and keep checking the
size until it matches, but I haven't come up with an elegent way to do it
yet. I'm sure there is a better way too. Any input would help. My brain
hurts at the moment.

[1]::WatchDirChange.cmd
[2]@echo off
[3]setlocal
[5]set src=E:\temp\test\
[6]set mask=????.txt
[7]set old=%temp%\old.txt
[8]set new=%temp%\new.txt
[9]set change=%temp%\change.txt
[10]
[11]if not exist %old% (call :GetList %src%%mask% %old%)
[12]echo Watching %src% for changes
[13]:Loop
[14]:: Create the current directory listing
[15]Call :GetList %src%%mask% %new%
[16]findstr /l /i /x /v /g:%old% %new% > %change%
[17]::0 = new entries 1 = no new entries
[18]if errorlevel 1 (Echo.%time% - No new files
[19]del %old%&ren %new% old.txt
[20]ping -n 10 127.0.0.1>nul 2>&1&goto :loop)
[21]echo New file(s) found.
[22]echo:&type %change% | more
[23]:checksize
[24]:: Best way to check the size of the new file/files against current
listing?
[25]goto :loop
[26]goto :eof
[27]
[28]:GetList
[29]for %%a in (%1) do echo %%~nxa %%~za %%~ta>>%2
[30]goto :eof

Thanks

Matt
 
I've come up with this so far but I'm having trouble figuring out the
best way to verify that the file is finished downloading before processing
it. The obvious way is just start another inner loop and keep checking the
size until it matches, but I haven't come up with an elegent way to do it
yet.

You will then have an issue with data timeouts and retries creating
large and unknown delays.

Can you use a download manager? I believe some can post-process their
files with a configurable program.
 
You will then have an issue with data timeouts and retries creating
large and unknown delays.

Can you use a download manager? I believe some can post-process their
files with a configurable program.

I can use anything I need, but this is a FTP push comming from one of our
clearing houses, so I'm not sure how a download manager would fit into the
picture. I've haven't used one since the dial up days though, so they might
have alot more functionality now. Do you have any recommendations for one
that will work with incomming files this way?
 
Hi Matt,

have you yet tried to use robocopy?
The XP-Version of robocopy has an option to monitor directories.

Regards Thomas Langer
 
Back
Top