Xceed .NET Libraries Documentation
Folder synchronization
Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Synchronization > The synchronization algorithm > Folder synchronization

An important distinction must be made between the behavior of synchronizing files, on the one hand, and synchronizing folders (as well as synchronizing folders together with files), on the other. When no folders are passed to the synchronization method, file names are not pertinent. For example, let's say you are working with file1.txt, file2.txt, and file3.txt, where file1.txt is the most recently modified (and hence will be considered by the synchronization algorithm to be the most up to date and therefore master item). If passed either as individual items (in this case, DiskFile objects) or in an array of DiskFile objects, the files are synchronized among themselves. In other words, the contents of file1.txt (along with its attributes) are used to overwrite the other files, regardless of their names.

However, if folders are passed, the synchronization is only performed on files with the same name. For example, if you pass two folders (say, folder01 and folder02), each of which contains versions of these three files, folder01\file1.txt would only be synchronized with folder02\file1.txt; folder01\file2.txt and folder02\file2.txt would synchronize to the most recently modified version of that file, as would folder01\file3.txt and folder02\file3.txt. If on the other hand one or more file items are passed with folders, only the file items corresponding to the passed files will be synchronized. For example, if file1.txt, folder01, and folder02 are passed, only file1.txt will be synchronized. The other files in our example (file2.txt and file3.txt) in the passed folders will not be synchronized. Furthermore, empty folders will be created.

Care must be therefore be taken not to simply build a list of different files and synchronize them. As described above, this will result in all of the files being synchronized to the most recently modified file, regardless of the names of the files. If this is not the desired result, data loss will occur.