本帖最后由 xianghongai 于 2011-11-07 09:39:30 编辑

解决方案 »

  1.   

    //路径名
                string DirName = @"e:\";
                //文件中包含名
                string FileName = "aa";            GetFileName(DirName,FileName);
    public static void GetFileName(string DirName, string FileName)
            {
                //文件夹信息
                DirectoryInfo dir = new DirectoryInfo(DirName);
                //如果非根路径且是系统文件夹则跳过
                if (null != dir.Parent && dir.Attributes.ToString().IndexOf("System") > -1)
                {
                    return;
                }
                //取得所有文件
                FileInfo[] finfo = dir.GetFiles();
                string fname = string.Empty;
                for (int i = 0; i < finfo.Length; i++)
                {
                    fname = finfo[i].Name;
                    //判断文件是否包含查询名
                    if (fname.IndexOf(FileName) > -1)
                    {
                        Console.WriteLine(finfo[i].FullName);
                    }
                }
                //取得所有子文件夹
                DirectoryInfo[] dinfo = dir.GetDirectories();
                for (int i = 0; i < dinfo.Length; i++)
                {
                    //查找子文件夹中是否有符合要求的文件
                    GetFileName(dinfo[i].FullName, FileName);
                }
            }
      

  2.   


    public class Main { public static void main(String[] args) {
    File file = new File("D:\\sqlite3.exe");
    System.out.println(getName(file));
    } public static String getName(File file) {
    String name = file.getName();
    if (file.toString().length() == 3) {
    name = file.toString().substring(0, 1);
    }
    if (file.isFile()) {
    int index = name.lastIndexOf(".");
    name = name.substring(0, index);
    }
    return name;
    }
    }需要保证传过来的文件在硬盘中存在的,当然你都能打开那就没问题。
      

  3.   


    string ss =@"F:\sdadsadasda\sdasd\asd\";
            int i=ss.LastIndexOf(@"\");
            int j = ss.IndexOf(":");
            if (ss.Substring(i + 1) != "")
                TextBox2.Text = ss.Substring(i + 1);
            else
                TextBox2.Text = ss.Substring(0,j);
      

  4.   


            public string test(string s)
            {
                string t = s.Substring(s.IndexOf('/'), s.Length);
                return t;
            }
      

  5.   

    上面那个方法写错0.0        public string test(string s)
            {
                string t = s.Substring(s.IndexOf('/'), s.Length-s.IndexOf('/'));
                return t;
            }