.Net - UTC Compare.

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
Not delved into UTC much but hope it could be the solution to a problem.

I have a small app running that on the hour, every hour, goes through a directory and compares files on a server to those in a local directory.

If a file on the server is not found locally then it downloads it, no probs.

But I need to compare the files themselves as files on the server may be updated: here's where my problem is.

I can't use a byte by byte comparrison because the FileStream object won't allow URI.

So the only other option was to compare the dates of the files.

Problem is, at present I'm comparing the Creation Date/Time, but if I upload it to the server at 10:00:00 and download it and store it localled 30mins later, the creation time locally is 10:30:00 even though it's the same file!

Next hour comes along, the file on the server is still 10:00:00, the file locally is different, so it re-downloads it and saves its creation time as 11:30:00 and on and on and on.

Would looking at UTC solve this issue? If I had a file created on my PC at 16:30:33 and I uploaded it onto a server at 17:03:12 and downloaded it locally at 17:56:46 the UTC Creation time would be 16:30:33?

(hope I've explained that good)
 
A few quick thoughts:

You can modify the time and date properties of the file so just make them match.

Or

Instead of polling for new files you could be more event driven. .Net has a built in FileMonitorWatcherThingy class that will monitor for changes to a directory or file system and fire an event when this happens. From here you could either keep a list of what's changed or do the download there and then.

Or

Ditch the app and write a batch file that uses xcopy (which does this perfectly) and use Windows Scheduler to run it every hour.
 
Back
Top Bottom