本文整理汇总了C#中WIN32_FIND_DATA类的典型用法代码示例。如果您正苦于以下问题:C# WIN32_FIND_DATA类的具体用法?C# WIN32_FIND_DATA怎么用?C# WIN32_FIND_DATA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WIN32_FIND_DATA类属于命名空间,在下文中一共展示了WIN32_FIND_DATA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindFirstFile
internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
{
fileName = PathInternal.EnsureExtendedPrefixOverMaxPath(fileName);
// use FindExInfoBasic since we don't care about short name and it has better perf
return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
}
示例2: WIN32_FIND_DATA
private IEnumerable<string>GetFiles(string dir)
{
WIN32_FIND_DATA findFileData = new WIN32_FIND_DATA();
IntPtr h = FindFirstFile(dir, ref findFileData);
if (h == INVALID_HANDLE_VALUE) {
yield break;
}
try {
do {
if (findFileData.cFileName == "." || findFileData.cFileName == "..") {
continue;
}
if ((findFileData.dwFileAttributes & 0x00000010u) == 0) {
yield return findFileData.cFileName;
}
else {
yield return string.Concat(findFileData.cFileName, "\\");
}
} while (FindNextFile(h, ref findFileData) != 0);
}
finally {
if ((int)h > 0) {
int ret = FindClose(h);
if (ret == 0) {
throw new Exception();
}
}
}
}
示例3: subObjectExists
private bool subObjectExists(bool fDirectory) {
if(hFindFile != INVALID_HANDLE_VALUE) {
if((fDirectory && fSubDirectoryFound) || (!fDirectory && fSubFileFound)) {
return true;
}
if(iLastError == 0x12) {
return false;
}
int num = 0;
WIN32_FIND_DATA lpFindFileData = new WIN32_FIND_DATA();
int uMode = SetErrorMode(1);
try {
if(hFindFile == IntPtr.Zero) {
hFindFile = FindFirstFile(path, lpFindFileData);
}
if(hFindFile != INVALID_HANDLE_VALUE) {
do {
if(((lpFindFileData.cFileName != null) && (lpFindFileData.cFileName != ".")) && (lpFindFileData.cFileName != "..")) {
if((fSearchHidden || ((lpFindFileData.dwFileAttributes & 2) == 0)) && (fSearchSystem || ((lpFindFileData.dwFileAttributes & 4) == 0))) {
if((lpFindFileData.dwFileAttributes & 0x10) != 0) {
fSubDirectoryFound = true;
if(fDirectory) {
return true;
}
}
else {
fSubFileFound = true;
if(!fDirectory) {
return true;
}
}
}
if(++num > 0x20) {
if(fDirectory) {
fSubDirectoryFound = true;
}
else {
fSubFileFound = true;
}
return true;
}
}
}
while(FindNextFile(hFindFile, lpFindFileData));
iLastError = Marshal.GetLastWin32Error();
}
}
finally {
SetErrorMode(uMode);
}
}
return false;
}
示例4: PopulateFrom
internal void PopulateFrom(ref WIN32_FIND_DATA findData)
{
// Copy the information to data
fileAttributes = (int)findData.dwFileAttributes;
ftCreationTimeLow = findData.ftCreationTime.dwLowDateTime;
ftCreationTimeHigh = findData.ftCreationTime.dwHighDateTime;
ftLastAccessTimeLow = findData.ftLastAccessTime.dwLowDateTime;
ftLastAccessTimeHigh = findData.ftLastAccessTime.dwHighDateTime;
ftLastWriteTimeLow = findData.ftLastWriteTime.dwLowDateTime;
ftLastWriteTimeHigh = findData.ftLastWriteTime.dwHighDateTime;
fileSizeHigh = findData.nFileSizeHigh;
fileSizeLow = findData.nFileSizeLow;
}
示例5: FileData
/// <summary>
/// Initializes a new instance of the <see cref="FileData"/> class.
/// </summary>
/// <param name="dir">The directory that the file is stored at</param>
/// <param name="findData">WIN32_FIND_DATA structure that this
/// object wraps.</param>
internal FileData(string dir, WIN32_FIND_DATA findData)
{
this.Attributes = findData.dwFileAttributes;
this.CreationTimeUtc = ConvertDateTime(findData.ftCreationTime_dwHighDateTime,
findData.ftCreationTime_dwLowDateTime);
this.LastAccessTimeUtc = ConvertDateTime(findData.ftLastAccessTime_dwHighDateTime,
findData.ftLastAccessTime_dwLowDateTime);
this.LastWriteTimeUtc = ConvertDateTime(findData.ftLastWriteTime_dwHighDateTime,
findData.ftLastWriteTime_dwLowDateTime);
this.Size = CombineHighLowInts(findData.nFileSizeHigh, findData.nFileSizeLow);
this.Name = findData.cFileName;
this.Path = System.IO.Path.Combine(dir, findData.cFileName);
}
示例6: GetRemovableStorageDirectory
public static string GetRemovableStorageDirectory()
{
string removableStorageDirectory = null;
IntPtr handle = IntPtr.Zero;
try
{
WIN32_FIND_DATA findData = new WIN32_FIND_DATA();
handle = FindFirstFlashCard(ref findData);
if(handle != INVALID_HANDLE_VALUE)
{
do
{
if(!string.IsNullOrEmpty(findData.cFileName))
{
removableStorageDirectory = findData.cFileName;
break;
}
}
while(FindNextFlashCard(handle, ref findData));
}
}
catch
{
removableStorageDirectory = null;
}
finally
{
if(handle != INVALID_HANDLE_VALUE)
{
FindClose(handle);
}
}
return removableStorageDirectory;
}
示例7: FindFirstFlashCard
extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);
示例8: FindFirstFileExPrivate
private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags);
示例9: FindFirstFileEx
public static extern SafeFindFilesHandle FindFirstFileEx(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, FindFirstFileExFlags dwAdditionalFlags);
示例10: FindNextFile
public static extern bool FindNextFile(SafeFindFilesHandle hFindFile, out WIN32_FIND_DATA lpFindFileData);
示例11: FindNextFile
internal static extern bool FindNextFile(
SafeFindHandle hndFindFile,
ref WIN32_FIND_DATA lpFindFileData);
示例12: InternetFindNextFile
//UPGRADE_WARNING: Structure WIN32_FIND_DATA may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
public static extern int InternetFindNextFile(int hFind, ref WIN32_FIND_DATA lpvFindData);
示例13: FindFiles
public static IEnumerable<string> FindFiles(DirectoryInfo dir,
string pattern, SearchOption searchOption)
{
// We suppressed this demand for each p/invoke call, so demand it upfront once
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
// Validate parameters
if (dir == null)
throw new ArgumentNullException("dir");
if (pattern == null)
throw new ArgumentNullException("pattern");
// Setup
WIN32_FIND_DATA findData = new WIN32_FIND_DATA();
Stack<DirectoryInfo> directories = new Stack<DirectoryInfo>();
directories.Push(dir);
// Process each directory
ErrorModes origErrorMode = SetErrorMode(ErrorModes.FailCriticalErrors);
try
{
while (directories.Count > 0)
{
// Get the name of the next directory and the corresponding search pattern
dir = directories.Pop();
string dirPath = dir.FullName.Trim();
if (dirPath.Length == 0)
continue;
char lastChar = dirPath[dirPath.Length - 1];
if (lastChar != Path.DirectorySeparatorChar &&
lastChar != Path.AltDirectorySeparatorChar)
{
dirPath += Path.DirectorySeparatorChar;
}
// Process all files in that directory
SafeFindHandle handle = FindFirstFile(dirPath + pattern, findData);
if (handle.IsInvalid)
{
int error = Marshal.GetLastWin32Error();
if (error == ERROR_ACCESS_DENIED ||
error == ERROR_FILE_NOT_FOUND)
{
continue;
}
else
{
throw new Win32Exception(error);
}
}
else
{
try
{
do
{
if ((findData.dwFileAttributes &
FileAttributes.Directory) == 0)
yield return (dirPath + findData.cFileName);
}
while (FindNextFile(handle, findData));
int error = Marshal.GetLastWin32Error();
if (error != ERROR_NO_MORE_FILES)
{
throw new Win32Exception(error);
}
}
finally
{
handle.Dispose();
}
}
// Add all child directories if that's what the user wants
if (searchOption == SearchOption.AllDirectories)
{
foreach (DirectoryInfo childDir in dir.GetDirectories())
{
if ((File.GetAttributes(childDir.FullName) &
FileAttributes.ReparsePoint) == 0)
{
directories.Push(childDir);
}
}
}
}
}
finally
{
SetErrorMode(origErrorMode);
}
}
示例14: FindFirstFile
private static extern IntPtr FindFirstFile(string lpFileName,
out WIN32_FIND_DATA lpFindFileData);
示例15: FindFirstFile
private static extern IntPtr FindFirstFile([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpFileName, ref WIN32_FIND_DATA lpFindFileData);