C#遍历文件后如何找回文件的绝对路径遍历了一个文件夹下面的所有JPG文件,文件名显示在LISTBOX上,如何通过文件名找到其所在的绝对路径...请高手指教...

解决方案 »

  1.   

    string[] files = Directory.GetFileSystemEntries(
    @"C:\Documents and Settings\aaron.zhang\My Documents\My Pictures\", "*.jpg");
      

  2.   

    TreeView和listView控件绑定文件夹及文件 ,可查看路径
    参考
      

  3.   

    GetFullPath
    string fileName = "myfile.ext";
    string path1 = @"mydir";
    string path2 = @"\mydir";
    string fullPath;fullPath = Path.GetFullPath(path1);
    Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
        path1, fullPath);fullPath = Path.GetFullPath(fileName);
    Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
        fileName, fullPath);fullPath = Path.GetFullPath(path2);
    Console.WriteLine("GetFullPath('{0}') returns '{1}'", 
        path2, fullPath);// Output is based on your current directory, except
    // in the last case, where it is based on the root drive
    // GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
    // GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
    // GetFullPath('\mydir') returns 'C:\mydir'
      

  4.   

     DirectoryInfo dir = new DirectoryInfo(@".\infosys");
     FileInfo[] files = dir.GetFiles("*.xls");
    //files[i].Name   文件名
    //files[i].FullName  绝对地址
      

  5.   

    每个文件file在遍历的时候都把file.Directory记录到一个数组或者一个List里
      

  6.   

    如果所有文件都在同一目录下,那就把目录保存起来,用保存的目录+ListBox中的文件名不就是路径了吗
    如果不在同一目录下,设置ListBox的DisplayMember,ValueMember属性
      

  7.   

    "C:\Documents and Settings\aaron.zhang\My Documents\My Pictures\"+filename;
      

  8.   

    是正确的,就是需要把*.xls该为你自己想要的找的文件扩展名.
    有关文件的操作问题,本人已经上传了文件浏览器的代码, 你可以下载来做参考.