// TODO - BCL match - add overload that has a 'searchOption' argument
public static string[] GetFiles(string path, string searchPattern)
{
using (TransactionScope scope = new TransactionScope())
using (KtmTransactionHandle ktmTx = KtmTransactionHandle.CreateKtmTransactionHandle())
{
string dirSpec = System.IO.Path.Combine(path, searchPattern);
NativeMethods.WIN32_FIND_DATA findFileData;
SafeFileHandle hFind = FindFirstFileTransacted(dirSpec, ktmTx, out findFileData);
try
{
List <string> files = new List <string>();
// List all the other files in the directory.
do
{
files.Add(findFileData.cFileName);
}while (NativeMethods.FindNextFile(hFind, out findFileData));
int error = Marshal.GetLastWin32Error();
if (error != NativeMethods.ERROR_NO_MORE_FILES)
{
NativeMethods.HandleCOMError(error);
}
scope.Complete();
return(files.ToArray());
}
finally
{
// Ignore failures from this api just as the BCL does...
NativeMethods.FindClose(hFind);
}
}
}