Respond to new files in a directory

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
 
M

Mark V

In alt.msdos.batch.nt Matt Williamson wrote:

Multi-Post
Newsgroups:
alt.msdos.batch.nt,microsoft.public.win2000.cmdprompt.admin

No Follow-Up set.

Responding here only ( alt.msdos.batch.nt )
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
[ ]

Just a thought. May be nothing.
Could this just be a delayed write issue where change detection is
not triggered because the file change has not yet been commited?
Does running Sysinternals SYNC.EXE in a loop make any difference?
2 cents.
 
M

Matt Williamson

Multi-Post
Newsgroups:
alt.msdos.batch.nt,microsoft.public.win2000.cmdprompt.admin

Actually, I cross-posted 2x. After a couple of hours, I didn't see my post,
so I re-sent it thinking my news server didn't get it.
Just a thought. May be nothing.
Could this just be a delayed write issue where change detection is
not triggered because the file change has not yet been commited?
Does running Sysinternals SYNC.EXE in a loop make any difference?
2 cents.

I haven't tried out SYNC, I'll give it a shot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top