我正在尝试从一堆文件中提取元数据。这些文件可以是图像、视频或任何类型。我想从文件中提取所有可用的元数据,无论类型如何。我尝试使用WindowsAPICodePack和Shell32。我能够提取一堆属性,但我需要文件中提供的“投影类型”元数据。但两者WindowsAPICodePack都Shell32未能提取相同的内容。有什么解决办法吗?
这是Shell 32我尝试过的代码
List<string> arrHeaders = new List<string>();
List<Tuple<int, string, string>> attributes = new List<Tuple<int, string, string>>();
Shell32.Shell shell = new Shell32.Shell();
var strFileName = @"C:\Users\Admin\Google Drive\image.jpg";
Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));
for (int i = 0; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}
// The attributes list below will contain a tuple with attribute index, name and value
// Once you know the index of the attribute you want to get,
// you can get it directly without looping, like this:
var Authors = objFolder.GetDetailsOf(folderItem, 20);
for (int i = 0; i < arrHeaders.Count; i++)
{
var attrName = arrHeaders[i];
var attrValue = objFolder.GetDetailsOf(folderItem, i);
var attrIdx = i;
attributes.Add(new Tuple<int, string, string>(attrIdx, attrName, attrValue));
Debug.WriteLine("{0}\t{1}: {2}", i, attrName, attrValue);
}
Console.ReadLine();
WindowsAPICodePack下面给出了代码。
ShellObject file = ShellObject.FromParsingName(path);
var props = file.Properties.DefaultPropertyCollection;
var camera = file.Properties.GetProperty(SystemProperties.System.Photo.CameraModel);
aluckdog
相关分类