是否有人能够帮助我如何从Windows对象获取文件属性,即FileSize,FileType,Year,Label,DateModified,FileVersion。我已经尝试访问FileInfo类中的信息,它似乎没有我正在寻找的所有必要属性。我可以使用哪些其他库来访问这些信息,如果您可以提供示例,谢谢
答案 0 :(得分:1)
其中一些在FileInfo中已经可用(长度是文件大小,修改日期只是LastWriteTime)。部分信息可从FileVersionInfo获得。 'type'有点棘手,但是this帖子有一些关于在注册表中查找mime类型的信息。这在Windows 7上对我有用:
private static string GetType(string fileName)
{
string type = "Unknown";
string ext = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (regKey != null && regKey.GetValue("") != null)
{
string lookup = regKey.GetValue("").ToString();
if (!string.IsNullOrEmpty(lookup))
{
var lookupKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(lookup);
if (lookupKey != null)
{
type = lookupKey.GetValue("").ToString();
}
}
}
return type;
}
它将生成您在文件属性的详细标签页中看到的类型。例如,exe的'Application'和bmp的'Bitmap Image'。
答案here使用windows api函数shgetfileinfo获取类型。
答案 1 :(得分:0)
嘿,请查看MSDN:http://msdn.microsoft.com/en-us/library/system.io.file.aspx
示例
GetCreationTime ()
GetLastWriteTime ()