This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!-- Include this target at the end of your project file to allow properties to be fully initialized --> | |
<!-- Set up common properties for T4 text templating --> | |
<ItemGroup> | |
<!-- Release, debug, etc. --> | |
<T4ParameterValues Include="Configuration"> | |
<Value>$(Configuration)</Value> | |
</T4ParameterValues> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.IO | |
{ | |
public static class Path | |
{ | |
public static ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path); | |
public static ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path); | |
public static ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path); | |
public static bool HasExtension(ReadOnlySpan<char> path); | |
public static bool IsPathFullyQualified(ReadOnlySpan<char> path); | |
public static bool IsPathRooted(ReadOnlySpan<char> path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.IO | |
{ | |
public class EnumerationOptions | |
{ | |
/// <summary> | |
/// Default constructor. Constructs the options class with recommended default options. | |
/// </summary> | |
public EnumerationOptions() | |
{ | |
IgnoreInaccessible = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerable<string> fileAndDirectoryNames = | |
new FileSystemEnumerable<string>(@"C:\", (ref FileSystemEntry entry) => entry.FileName.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerable<string> fileNames = | |
new FileSystemEnumerable<string>( | |
@"C:\test", | |
(ref FileSystemEntry entry) => entry.FileName.ToString()) | |
{ | |
ShouldIncludePredicate = (ref FileSystemEntry entry) => !entry.IsDirectory | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<FileInfo> GetFilesWithExtensions(string directory, | |
bool recursive, params string[] extensions) | |
{ | |
return new FileSystemEnumerable<FileInfo>( | |
directory, | |
(ref FileSystemEntry entry) => (FileInfo)entry.ToFileSystemInfo(), | |
new EnumerationOptions() { RecurseSubdirectories = recursive }) | |
{ | |
ShouldIncludePredicate = (ref FileSystemEntry entry) => | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int CountFiles(string directory, bool recursive) | |
{ | |
return (new FileSystemEnumerable<int>( | |
directory, | |
(ref FileSystemEntry entry) => 1, | |
new EnumerationOptions() { RecurseSubdirectories = recursive }) | |
{ | |
ShouldIncludePredicate = (ref FileSystemEntry entry) => !entry.IsDirectory | |
}).Count(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long CountFileBytes(string directory, bool recursive) | |
{ | |
return (new FileSystemEnumerable<long>( | |
directory, | |
(ref FileSystemEntry entry) => entry.Length, | |
new EnumerationOptions() { RecurseSubdirectories = recursive }) | |
{ | |
ShouldIncludePredicate = (ref FileSystemEntry entry) => !entry.IsDirectory | |
}).Sum(); | |
} |
OlderNewer