是否有可能在 .NET Standard 中获得免费驱动器 space?

Is possible to get drive free space in .NET Standard?

我有 3 个项目:

1 - .NET Core 应用程序

2 - .NET Framework 应用程序

3 - .NET Standard 库,其中是第一个和第二个应用程序项目的通用代码。

...我想在 .NET Standard 库中检查我的驱动器空闲 space 以执行其他以下操作。可能吗?怎么样?

DriveInfo 是一个依赖于系统的 InteropServices,因为驱动器的名称和属性在 Linux 和 Windows 之间是不同的。但是它在两个世界都实现了。

using System;
using System.IO;

//...

    DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  Free:{0, 15} bytes", d.AvailableFreeSpace);            
    }