Skip to content

Instantly share code, notes, and snippets.

@JeremyKuhne
Created March 8, 2018 05:54
Show Gist options
  • Save JeremyKuhne/dab62d0212dc453a57a28f4e9df406ea to your computer and use it in GitHub Desktop.
Save JeremyKuhne/dab62d0212dc453a57a28f4e9df406ea to your computer and use it in GitHub Desktop.
FileSystemEntry
namespace System.IO.Enumeration
{
public ref struct FileSystemEntry
{
// The directory this entry (file/directory) lives in
public ReadOnlySpan<char> Directory { get; }
// The fully qualified root directory of the enumeration
public ReadOnlySpan<char> RootDirectory { get; }
// The root directory as provided to the constructor
public ReadOnlySpan<char> OriginalRootDirectory { get; }
// The name of the file/directory
public ReadOnlySpan<char> FileName { get; }
public FileAttributes Attributes { get; }
public long Length { get; }
public DateTimeOffset CreationTimeUtc { get; }
public DateTimeOffset LastAccessTimeUtc { get; }
public DateTimeOffset LastWriteTimeUtc { get; }
// Using IsDirectory/IsHidden is optimized over using Attributes.
// (Getting the full set of attributes hits the disk on Unix)
public bool IsDirectory { get; }
public bool IsHidden { get; }
// Creating File/DirectoryInfo through this method is internally optimized.
public FileSystemInfo ToFileSystemInfo();
// This is the path that you historically got from enumeration APIs. It is based off the specifed root path. (OriginalRootDirectory)
public string ToSpecifiedFullPath();
// This is the fully qualified path to the directory/file.
public string ToFullPath();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment