我想要一个显示媒体文件的一些文件属性(如果可用)的应用程序,比如(不知道 Windows 中使用的确切英文单词)文件名、长度/持续时间、文件类型(.avi .mp3 等)我试过 taglib和 windowsapishell 但我没有得到工作结果(参考很好)
ShellFile so = ShellFile.FromFilePath(file);
so.Properties.System.(everythingIwant)
向我展示了很多我想要显示的文件属性,但我无法让它工作一个错误示例:
'WindowsFormsApplication2.vshost.exe'(托管 (v4.0.30319)):加载 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll',跳过加载符号。模块已优化,调试器选项“仅我的代码”已启用。程序“[6300] WindowsFormsApplication2.vshost.exe:程序跟踪”已退出,代码为 0 (0x0)。程序“[6300] WindowsFormsApplication2.vshost.exe: Managed (v4.0.30319)”已退出,代码为 0 (0x0)。
像这样简单的东西
var thing = so.Properties.System.FileName.Description;
Console.WriteLine(thing);
不会工作
我确实知道一些 Java 和 PHP 编程,但我对 C# 完全陌生
特别感谢@marr75 和@errorstacks!
一个后续问题:我做了这个,它有效
class Program
{
static void Main(string[] args)
{
string file = "E:/Dump/Shutter Island.avi";
FileInfo oFileInfo = new FileInfo(file);
Console.WriteLine("My File's Name: \"" + oFileInfo.Name + "\"");
DateTime dtCreationTime = oFileInfo.CreationTime;
Console.WriteLine("Date and Time File Created: " + dtCreationTime.ToString());
Console.WriteLine("myFile Extension: " + oFileInfo.Extension);
Console.WriteLine("myFile total Size: " + oFileInfo.Length.ToString());
Console.WriteLine("myFile filepath: " + oFileInfo.DirectoryName);
Console.WriteLine("My File's Full Name: \"" + oFileInfo.FullName + "\"");
}
}
但我希望它只在信息存在的情况下向我提供信息。我看到了
**Exists** Gets a value indicating whether a file exists. (Overrides FileSystemInfo.Exists.)
但是我该如何使用这个功能,我猜不像 if(io.ofileinfo.FullName.exist) {Console.Write(io.ofileinfo.fullname);} ?