We have implemented a similar function using C #. FileSystemWatcher was inefficient with large directory trees.
Our alternative, used FSNodes , the structure we created using the following Windows API calls:
[StructLayout(LayoutKind.Sequential)] private struct FILETIME { public uint dwLowDateTime; public uint dwHighDateTime; }; [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] private struct WIN32_FIND_DATA { public FileAttributes dwFileAttributes; public FILETIME ftCreationTime; public FILETIME ftLastAccessTime; public FILETIME ftLastWriteTime; public uint nFileSizeHigh; public uint nFileSizeLow; public int dwReserved0; public int dwReserved1; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAX_PATH)] public string cFileName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAX_ALTERNATE)] public string cAlternate; } [DllImport("kernel32.dll", SetLastError = true)] static extern bool FindClose(IntPtr hFindFile); [DllImport("kernel32", CharSet=CharSet.Unicode)] private static extern IntPtr FindFirstFile( string lpFileName, out WIN32_FIND_DATA lpFindFileData); [DllImport("kernel32", CharSet=CharSet.Unicode)] private static extern bool FindNextFile( IntPtr hFindFile, out WIN32_FIND_DATA lpFindFileData);
We do static processing. We save the metadata tree on disk and compare the stored directory tree with the loaded one, the search has been changed (based on its timestamp (faster) or file hash). In addition, we can manage deleted, added and moved, even moved files (also based on the file hash).
This implementation, mixed with the daemon that executed it every POLL_TIME, is valid for us. Hope this helps.
Daniel PeΓ±alba
source share