52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using PInvoke;
|
|
|
|
namespace AssetBrowser
|
|
{
|
|
class BasicFileEnumerator : FileEnumerator
|
|
{
|
|
public IEnumerable<string> GetAllFiles(string _folder)
|
|
{
|
|
if (String.IsNullOrEmpty(_folder))
|
|
yield break;
|
|
|
|
if (!Directory.Exists(_folder))
|
|
yield break;
|
|
|
|
foreach (string file in EnumerateDir(_folder))
|
|
{
|
|
yield return file;
|
|
}
|
|
}
|
|
|
|
private IEnumerable<string> EnumerateDir(string _folder)
|
|
{
|
|
Win32Api.WIN32_FIND_DATA findData;
|
|
string searchString = Path.Combine(_folder, "*");
|
|
IntPtr hFind = Win32Api.FindFirstFile(searchString, out findData);
|
|
if (hFind.ToInt32() != Win32Api.INVALID_HANDLE_VALUE)
|
|
{
|
|
do
|
|
{
|
|
if ((findData.dwFileAttributes & Win32Api.FILE_ATTRIBUTE_DIRECTORY) != 0)
|
|
{
|
|
if (findData.cFileName != "." && findData.cFileName != "..")
|
|
{
|
|
foreach (string filename in EnumerateDir(Path.Combine(_folder, findData.cFileName)))
|
|
yield return filename;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
yield return findData.cFileName;
|
|
}
|
|
} while (Win32Api.FindNextFile(hFind, out findData));
|
|
Win32Api.FindClose(hFind);
|
|
}
|
|
}
|
|
}
|
|
}
|