100 lines
2.9 KiB
C#
100 lines
2.9 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Net;
|
|||
|
using System.Windows;
|
|||
|
using System.Windows.Controls;
|
|||
|
using System.Windows.Documents;
|
|||
|
using System.Windows.Ink;
|
|||
|
using System.Windows.Input;
|
|||
|
using System.Windows.Media;
|
|||
|
using System.Windows.Media.Animation;
|
|||
|
using System.Windows.Shapes;
|
|||
|
|
|||
|
namespace FileSystemApi
|
|||
|
{
|
|||
|
public class Directory
|
|||
|
{
|
|||
|
public static string[] GetFiles(string path, string searchString)
|
|||
|
{
|
|||
|
var fileList = new List<string>();
|
|||
|
|
|||
|
IntPtr hFind = IntPtr.Zero;
|
|||
|
WIN32_FIND_DATA findData;
|
|||
|
|
|||
|
string fullPathQuery = System.IO.Path.Combine(path, searchString);
|
|||
|
|
|||
|
int ret = FileSystem.FindFirstFile(fullPathQuery, out findData, out hFind);
|
|||
|
|
|||
|
if(ret == 0 || hFind == new IntPtr(-1))
|
|||
|
{
|
|||
|
return fileList.ToArray();
|
|||
|
}
|
|||
|
|
|||
|
if( (findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory )
|
|||
|
{
|
|||
|
fileList.Add(findData.cFileName);
|
|||
|
}
|
|||
|
|
|||
|
while(true)
|
|||
|
{
|
|||
|
ret = FileSystem.FindNextFile(hFind, out findData);
|
|||
|
|
|||
|
if(ret == 0)
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if ((findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
|
|||
|
{
|
|||
|
fileList.Add(findData.cFileName);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FileSystem.FindClose(hFind);
|
|||
|
return fileList.ToArray();
|
|||
|
}
|
|||
|
|
|||
|
public static string[] GetDirectories(string path, string searchString)
|
|||
|
{
|
|||
|
var fileList = new List<string>();
|
|||
|
|
|||
|
IntPtr hFind = IntPtr.Zero;
|
|||
|
WIN32_FIND_DATA findData;
|
|||
|
|
|||
|
string fullPathQuery = System.IO.Path.Combine(path, searchString);
|
|||
|
|
|||
|
int ret = FileSystem.FindFirstFile(fullPathQuery, out findData, out hFind);
|
|||
|
|
|||
|
if (ret == 0 || hFind == new IntPtr(-1))
|
|||
|
{
|
|||
|
int err = Microsoft.Phone.InteropServices.Marshal.GetLastWin32Error();
|
|||
|
return fileList.ToArray();
|
|||
|
}
|
|||
|
|
|||
|
if ((findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|||
|
{
|
|||
|
fileList.Add(findData.cFileName);
|
|||
|
}
|
|||
|
|
|||
|
while (true)
|
|||
|
{
|
|||
|
ret = FileSystem.FindNextFile(hFind, out findData);
|
|||
|
|
|||
|
if (ret == 0)
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if ((findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|||
|
{
|
|||
|
fileList.Add(findData.cFileName);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
FileSystem.FindClose(hFind);
|
|||
|
return fileList.ToArray();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|