在.NET中找到总的和可用的磁盘空间 [英] Finding out total and free disk space in .NET

查看:122
本文介绍了在.NET中找到总的和可用的磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种从.NET应用程序确定任意文件夹中的总和可用磁盘空间的方法。通过文件夹中的总磁盘空间和可用磁盘空间,我参考了如果您在其上执行dir命令,则该文件夹将报告的总和可用磁盘空间,即总共和可用磁盘空间包含该文件夹的逻辑驱动器,考虑到要求请求的用户帐户。

I am trying to find a way to determine the total and available disk space in an arbitrary folder from a .NET app. By "total disk space" and "available disk space" in a folder I refer to the total and available disk space that this folder would report if you performed a "dir" command on it, that is, the total and available disk space of the logical drive containing that folder, considering the user account under which the request is being made.

我正在使用C#。该方法应适用于作为UNC路径给出的本地和远程文件夹(而不是通过映射的驱动器号进行访问)。例如,它应该适用于:

I am using C#. The method should work both for local and remote folders given as UNC paths (rather than accessed through mapped drive letters). For example, it should work for:


  • C:\Temp

  • \\ Silfen\Resources\Temp2

我从一个DirectoryInfo对象开始,但这似乎没有相关的磁盘空间信息。 DriveInfo类没有,但它不会与远程文件夹一起使用。

I am starting with a DirectoryInfo object, but this seems to have no associated disk space information. The DriveInfo class does, but it won't work with remote folders.

编辑。与你们交流之后,我正在考虑映射远程文件夹作为本地驱动器,使用DriveInfo获取数据,并重新取消映射。这种方法的问题是,我的应用程序需要每天多次收集超过120个文件夹的数据,每天几次。我不知道这是否可行。

Edit. After some exchanges with you guys, I am considering mapping remote folders as local drives, using DriveInfo to obtain the data, and unmapping again. The problem with this approach is that my app needs to collect the data for over 120 folders a few times a day, every day. I am not sure this would be feasible.

任何想法?谢谢。

推荐答案

来自MSDN的此链接使用 System.IO.DriveInfo 类?

这篇关于在.NET中找到总的和可用的磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆