如何让文件属性? [英] how to get file properties?

查看:152
本文介绍了如何让文件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这显示一个媒体文件,如果提供的一些文件属性,如应用程序(不知道在Windows中使用它确切的英文单词)的文件名,距离/时间,文件类型(.AVI .MP3等)
我试着标签库和windowsapishell,但我没有得到一个工作结果(引用是好的)

I want an application which displays the some file properties of a mediafile if available, like (don't know the exact english words used in windows for it) FileName, Length/Duration, FileType(.avi .mp3 etc.) I tried taglib and windowsapishell but I dont get a working result (references are good)

ShellFile so = ShellFile.FromFilePath(file);
so.Properties.System.(everythingIwant)

显示了我很多,我希望显示的文件属性的,但我不能让它工作
一个错误的一个例子:

shows me a lot of file properties which I want to have displayed, but I cant get it working An example of an error:

WindowsFormsApplication2.vshost.exe(管理(v4.0.30319)):加载'C:\\Windows\\Microsoft.Net\\assembly\\GAC_MSIL\\WindowsBase\\v4.0_4.0.0.0__31bf3856ad364e35\\WindowsBase.dll',跳过加载符号。模块进行了优化和调试器选项仅我的code已启用。
该方案的[6300] WindowsFormsApplication2.vshost.exe:程序跟踪已退出与code 0(为0x0)。
该方案的[6300] WindowsFormsApplication2.vshost.exe:托管(v4.0.30319)'。已退出与code 0(为0x0)

'WindowsFormsApplication2.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The program '[6300] WindowsFormsApplication2.vshost.exe: Program Trace' has exited with code 0 (0x0). The program '[6300] WindowsFormsApplication2.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

东西容易像

var thing = so.Properties.System.FileName.Description;
Console.WriteLine(thing);

不会工作

我确实知道一些Java和PHP编程,但我完全新的C#

I do know some Java and PHP programming, but I'm totally new to C#

特别感谢@ marr75和@errorstacks!

Special thanks to @marr75 and @errorstacks !

一个跟进的问题:
我做了这个,和它的作品

one follow up question: I made this, and it works

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 + "\"");

    }               
}

但我想,如果信息存在,它只能提供给我的信息。
我看到了

but I want it to only provide me with the info if the info exists. I saw the

   **Exists**   Gets a value indicating whether a file exists. (Overrides FileSystemInfo.Exists.)

但我怎么使用这个功能,我想不喜欢,如果(io.ofileinfo.FullName.exist){Console.Write(io.ofileinfo.fullname);}

But how do I use this function, I guess not like if(io.ofileinfo.FullName.exist) {Console.Write(io.ofileinfo.fullname);} ?

推荐答案

你可以尝试这样的....使用C#

you can try like this ....using c#

在审查或打开一个文件,要得到它的名字,FileInfo类是配备了Name属性。下面是一个样本code:

When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code:

FileInfo oFileInfo = new FileInfo(strFilename);

if (FileName != null || FileName.Length == 0)
{
   MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\"");
   For  calculating the size of files it holds.
  MessageBox.Show("myFile total Size: " + oFileInfo.Length.ToString());

}

您可以检查像这样

if (!oFileInfo.Exists)
{
    throw new FileNotFoundException("The file was not found.", FileName);
}

要找出这些日期和时间值,可以使用访问文件系统信息属性。

To find out what those date and time values are, you can access the File System Information property using.

DateTime dtCreationTime = oFileInfo.CreationTime;
MessageBox.Show("Date and Time File Created: " + dtCreationTime.ToString());

要知道文件的扩展名,您可以访问FileSystemInfo.Extension属性的值。

To know the extension of the file, you can access the value of the FileSystemInfo.Extension property.

MessageBox.Show("myFile Extension: " + oFileInfo.Extension);

这篇关于如何让文件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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