protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            // dispose all
            if (disposing)
            {
                _currentFileHandle.Dispose();
                _currentFileHandle = null;
            }

            // done
            _disposed = true;
        }
        /// <summary>
        /// Moves to next element
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            do
            {
                // only at start currentFileHandle is null
                if (_currentFileHandle == null)
                {
                    // first call
                    _currentFileHandle = Win32SafeNativeMethods.FindFirstFile(DirectoryPath, _currentFindData);
                    _currentErrorCode  = Marshal.GetLastWin32Error();
                }
                else
                {
                    // second to n call
                    _currentFindData = new Win32FindData();
                    if (!Win32SafeNativeMethods.FindNextFile(_currentFileHandle, _currentFindData))
                    {
                        return(false);
                    }
                }

                // Take care of invalid handles
                if (_currentFileHandle.IsInvalid)
                {
                    if (_currentErrorCode != Win32ErrorCodes.ERROR_NO_MORE_FILES)
                    {
                        Win32ErrorCodes.NativeExceptionMapping(DirectoryPath, _currentErrorCode);
                    }

                    return(false);
                }

                // skip entries to ignore
            } while(FilterSystemEntries && _currentFindData.IsSystemDirectoryEntry());

            return(true);
        }
Beispiel #3
0
 public Win32FileSystemEntry(Win32FileHandle fileHandle, Win32FindData findData)
 {
     FileHandle = fileHandle;
     FindData   = findData;
 }
 public Win32FileSystemEntry( Win32FileHandle fileHandle, Win32FindData findData )
 {
     FileHandle = fileHandle;
     FindData = findData;
 }
 public static extern bool FindNextFile(Win32FileHandle findFileHandle, [In, Out, MarshalAs(UnmanagedType.LPStruct)] Win32FindData win32FindData);
 public static extern bool FindNextFile( Win32FileHandle findFileHandle, [In, Out, MarshalAs( UnmanagedType.LPStruct )] Win32FindData win32FindData );