【问题标题】:Is possible to get drive free space in .NET Standard? [closed]是否可以在 .NET Standard 中获得驱动器可用空间? [关闭]
【发布时间】:2019-01-09 10:50:58
【问题描述】:

我有 3 个项目:

1 - .NET Core 应用程序

2 - .NET 框架应用程序

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

...我想检查 .NET Standard 库中的驱动器可用空间以执行其他以下操作。是否可以?怎么样?

【问题讨论】:

标签: c# .net-standard drive diskspace


【解决方案1】:

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);            
    }

【讨论】:

    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    相关资源
    最近更新 更多