/// <summary> /// Builds a list of files in a folder under Win32. /// </summary> /// <param name="result"></param> /// <param name="path"></param> private void Win32GetFiles(List <FindFileData> result, string path) { if (path == null) { throw new ArgumentNullException(path); } path = String.Format("{0}{1}*", path, path.EndsWith(_PathSeparator) ? "" : _PathSeparator); IntPtr findHandle = IntPtr.Zero; FindFileData fileData; try { findHandle = FindFirstFile(path, out fileData); if (findHandle.ToInt32() != -1) { do { if ((fileData.dwFileAttributes & 0x00000010) == 0) { result.Add(fileData); // 0x10 is FILE_ATTRIBUTE_DIRECTORY } fileData = new FindFileData(); } while(FindNextFile(findHandle, out fileData)); } } finally { if (findHandle != IntPtr.Zero && findHandle.ToInt32() != -1) { FindClose(findHandle); } } }
public DefaultDirectoryCacheProviderFileInfo(FindFileData findFileData) { Name = findFileData.Name; LastWriteTimeUtc = findFileData.LastWriteTimeUtc; }
static extern bool FindNextFile(IntPtr hndFindFile, out FindFileData data);
static extern IntPtr FindFirstFile(string fileName, out FindFileData data);
/// <summary> /// Builds a list of files in a folder under Win32. /// </summary> /// <param name="result"></param> /// <param name="path"></param> private void Win32GetFiles(List<FindFileData> result, string path) { if(path == null) throw new ArgumentNullException(path); path = String.Format("{0}{1}*", path, path.EndsWith(_PathSeparator) ? "" : _PathSeparator); IntPtr findHandle = IntPtr.Zero; FindFileData fileData; try { findHandle = FindFirstFile(path, out fileData); if(findHandle.ToInt32() != -1) { do { if((fileData.dwFileAttributes & 0x00000010) == 0) result.Add(fileData); // 0x10 is FILE_ATTRIBUTE_DIRECTORY fileData = new FindFileData(); } while(FindNextFile(findHandle, out fileData)); } } finally { if(findHandle != IntPtr.Zero && findHandle.ToInt32() != -1) FindClose(findHandle); } }