Good question: I'll vote 5.
You may need P/Invoke to use WIN32.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct WIN32_FIND_DATA
{
public uint dwFileAttributes;
public System.Runtime.InteropServices.ComTypes.FILETIME
ftCreationTime;
public System.Runtime.InteropServices.ComTypes.FILETIME
ftLastAccessTime;
public System.Runtime.InteropServices.ComTypes.FILETIME
ftLastWriteTime;
public uint nFileSizeHigh;
public uint nFileSizeLow;
public uint dwReserved0;
public uint dwReserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
public string cAlternateFileName;
}
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr FindFirstFile(string lpFileName,
out WIN32_FIND_DATA lpFindFileData);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern bool FindNextFile(IntPtr hFindFile,
out WIN32_FIND_DATA lpFindFileData);
}
You see? Using
FindFirstFile
you find only one file, then you work with
FindNextFile
using a pointer returned by
FindFirstFile
.
Unfortunately, I don't see the how to implement
StartIndex
. However, you can think of some combination of this method with some renaming schema.