领导让我调用操作系统底层的native api,来获得文件大小和修改时间。
我不知道怎么用c#调用c++的系统api,能帮我封装成这两个c#函数GetFileSize和GetModifyTime吗?

解决方案 »

  1.   

    通过System.IO.File提供的静态方法获取, .net框架已经帮你封装好了
      

  2.   

    可以或者FileInfo也行
    先引入using System.Text;
    示例                FileInfo fi = new FileInfo(videopath);
                    string filename = Path.GetFileName(videopath);
                    string filetype = Path.GetExtension(videopath);
                    double size = Math.Round(fi.Length / (1024 * 1024d), 0);
                    string filesize = size.ToString() + "MB";
                    string[] name = filename.Split(new char[] { '_' });
      

  3.   

    领导说了,一定用操作系统底层的native api,就是在代码了添加那个DllImport("xxx.dll")]
      

  4.   

    那不是有毛病吗,.net框架也是封装了windows api
      

  5.   

     [DllImport("kernel32.dll", SetLastError =true)]
      internal static extern uint GetFileSize(IntPtr hFile, outuint highSize);
    参考
    http://hi.baidu.com/yimeng3025/blog/item/60b24afbb56c3fcfb48f3191.html
    其他几个函数
    GetFileSizeEx GetFileTime GetFileType
      

  6.   

    为什么一定要native api  ??????不明白,用意何在