【发布时间】:2012-01-11 05:02:24
【问题描述】:
我需要使用 C# 从“媒体创建”列(在下面的示例照片中以绿色突出显示)中提取日期。
在我的示例中,“媒体创建”和“日期”列完全相同。但是,有几种情况并非如此。 “媒体创建”列包含视频实际录制的正确日期。
这是我用来获取它的函数。感谢 Aziz 为我指明了正确的方向:
Shell shell = new ShellClass();
Folder folder = shell.NameSpace(_File.DirectoryName);
FolderItem file = folder.ParseName(_File.Name);
// These are the characters that are not allowing me to parse into a DateTime
char[] charactersToRemove = new char[] {
(char)8206,
(char)8207
};
// Getting the "Media Created" label (don't really need this, but what the heck)
string name = folder.GetDetailsOf(null, 191);
// Getting the "Media Created" value as a string
string value = folder.GetDetailsOf(file, 191).Trim();
// Removing the suspect characters
foreach (char c in charactersToRemove)
value = value.Replace((c).ToString(), "").Trim();
// If the value string is empty, return DateTime.MinValue, otherwise return the "Media Created" date
return value == string.Empty ? DateTime.MinValue : DateTime.Parse(value);
【问题讨论】:
-
1. 208 而不是 Windows 10 上的 191。 2. 代码应该在单线程单元 (STA) 中启动。使用 [STAThread] 属性或带有 ApartmentState.STA 的线程
-
如果你用的是Python,可以试试Getting metadata for MOV video。
-
感谢编辑,请问 ShellClass 类的程序集/命名空间是什么?