找出在.NET中总的和可用磁盘空间出在、磁盘空间、NET

2023-09-03 02:26:00 作者:孤心°

我试图找到一种方法来确定从.NET应用程序中的任意文件夹中的总的和可用的磁盘空间。通过总磁盘空间和可用磁盘空间文件夹中的我指的是总的和可用的磁盘空间,如果你在它执行的目录命令,这个文件夹将报告,也就是完全和可用磁盘空间包含该文件夹,考虑到正在取得下请求的用户帐户的逻辑驱动器。

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 \资源\ 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.

任何想法?谢谢你。

推荐答案

如何这个使用了 System.IO.DriveInfo 类?