从系统获取文件块大小。 [英] get the file block size from system.

查看:46
本文介绍了从系统获取文件块大小。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从系统中的文件中获取块和大小。

在同一个文件中读取和写入此块。

Get the block and size from the file in system.
Read & Write the this block in same file.

推荐答案

First总之,没有一个块大小。这是每个卷的特征,而不是整个系统的特征。



这根本不是一件小事。我更喜欢展示如何使用WMI,因为这样,您可以在纯C#中完成它。



考虑下面的代码,它显示每个卷的块大小:

First of all, there is no a single block size. This is a characteristic if each volume, not of the whole system.

This is not trivial thing at all. I prefer to show how to do it with WMI, because, this way, you can do it in pure C#.

Consider the following code which shows you the block size of each volume:
using System.Management;

//...

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Volume");
            ManagementObjectCollection collection = searcher.Get();
            foreach (ManagementObject item in collection) {
                System.Console.WriteLine("Name: {0}", item["Name"]);
                System.Console.WriteLine("Block size: {0}", item["BlockSize"]);
                System.Console.WriteLine();
            } // loop





如何运作?



查看类 ManagementObject

http://msdn.microsoft.com/en-us/ library / system.management.managementobject.aspx [ ^ ]。



如您所见,此类通过索引提供对运行时管理对象的不同属性的访问property''[]'',由字符串索引。你怎么知道要使用什么属性?

该类提供反射API;例如,您可以使用属性属性(和方法,以便您可以调用方法)。这个类实际上是一个可以通过查询获得的真实管理对象的包装。



但是在哪里阅读有关属性和方法的含义?您可以使用C ++文档来获取所需的属性。对于Win32_Volume,请使用

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394515%28v=vs.85%29.aspx [ ^ ]。



祝你好运,

-SA



How it works?

Look at the class ManagementObject:
http://msdn.microsoft.com/en-us/library/system.management.managementobject.aspx[^].

As you can see, this class provides access to different properties of a run-time management object via the indexed property ''[]'', indexed by strings. How do you know what property to use?
The class provides reflective API; for example, you can use the property Properties (and Methods, so you can invoke methods). This class is actually a wrapper over some "real" management objects you can get via a query.

But where to read about the meaning of the properties and method? You can use C++ documentation to get the properties you want. For Win32_Volume, use
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394515%28v=vs.85%29.aspx[^].

Good luck,

—SA


这篇关于从系统获取文件块大小。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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