File Synchronization/Backup
-
I would like to create a small app to synchronize/backup various groups of files or folders between a flashdrive, home pc and work pc. Any comments to ensure good speed and reliability regarding the following would be appreciated: 1) To determine which files have changed, <pre> Dim di As New DirectoryInfo(Path) Dim files As FileSystemInfo() = di.GetFiles Dim fi As FileInfo 'Loop through files and see when last modified, and add to a datatable For Each fi In files dr = dtFiles.NewRow dr.Item(0) = diNext.Name dr.Item(1) = dr.Item(0) = diNext.LastWriteTime dtFiles.Rows.Add(dr) Next </pre> Is this OK, or would it be better to check CRC of the files to find the ones that have changed? I was thinking more along the lines of determining which is the NEWEST file, and then making the sync Bi-Directional though 2) Once I have found the files that are newer, then use: <pre>System.IO.File.Copy("Sourcefile", "DestinationFile")</pre> To verify file copied correctly, maybe just put above in a Try... Catch... Or should I check CRC or something to see if copied correctly? 3) If anyone has done something similar, are there any pitfalls or things I should watch out for? Tks.
-
I would like to create a small app to synchronize/backup various groups of files or folders between a flashdrive, home pc and work pc. Any comments to ensure good speed and reliability regarding the following would be appreciated: 1) To determine which files have changed, <pre> Dim di As New DirectoryInfo(Path) Dim files As FileSystemInfo() = di.GetFiles Dim fi As FileInfo 'Loop through files and see when last modified, and add to a datatable For Each fi In files dr = dtFiles.NewRow dr.Item(0) = diNext.Name dr.Item(1) = dr.Item(0) = diNext.LastWriteTime dtFiles.Rows.Add(dr) Next </pre> Is this OK, or would it be better to check CRC of the files to find the ones that have changed? I was thinking more along the lines of determining which is the NEWEST file, and then making the sync Bi-Directional though 2) Once I have found the files that are newer, then use: <pre>System.IO.File.Copy("Sourcefile", "DestinationFile")</pre> To verify file copied correctly, maybe just put above in a Try... Catch... Or should I check CRC or something to see if copied correctly? 3) If anyone has done something similar, are there any pitfalls or things I should watch out for? Tks.
2). You can use File.Copy the copy the files over, wrapped in a Try/Catch block. You don't have to check the file contents yourself since the O/S takes care of that for you. Since File.Copy is a blocking call, any errors encountered will throw an exception you can catch. 3) Yeah, but I didn't write my own system to do this. I used the MS Sync Framework[^].
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...