Torna al Thread

void Main() { FindFiles(@"C:\Temp\*.txt"); FindFiles(@"C:\Temp\*.txto"); FindFiles(@"C:\Temp\*.txtold"); } public void FindFiles(string fullPath) { fullPath.Dump("FindFiles"); var data = new WIN32_FIND_DATA(); var hnd = FindFirstFile(fullPath, out data); data.Dump(hnd.ToString()); while (FindNextFile(hnd, out data)) { data.Dump(); } } public const int MAX_PATH = 260; public const int MAX_ALTERNATE = 14; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct WIN32_FIND_DATA { public FileAttributes dwFileAttributes; public FILETIME ftCreationTime; public FILETIME ftLastAccessTime; public FILETIME ftLastWriteTime; public uint nFileSizeHigh; //changed all to uint, otherwise you run into unexpected overflow public uint nFileSizeLow; //| public uint dwReserved0; //| public uint dwReserved1; //v [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string cFileName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ALTERNATE)] public string cAlternate; } [DllImport("kernel32.dll", BestFitMapping = false, CharSet = CharSet.Auto, ExactSpelling = false, SetLastError = true)] public static extern IntPtr FindFirstFile(string fileName, out WIN32_FIND_DATA lpFindFileData); [DllImport("kernel32.dll", BestFitMapping=false, CharSet=CharSet.Auto, ExactSpelling=false, SetLastError=true)] public static extern bool FindNextFile(IntPtr hndFindFile, out WIN32_FIND_DATA lpFindFileData);
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5