字符串类似“test/c66c3ef8/c2623bd2/App_global.asax.hmet2dpt.0.cs”
这样的
如果字符串最后面没有"/"则建文件夹“test/c66c3ef8/c2623bd2”
怎么写代码啊?

解决方案 »

  1.   


                string str = "test/c66c3ef8/c2623bd2/App_global.asax.hmet2dpt.0.cs";
                Directory.CreateDirectory(str.Substring(0, str.LastIndexOf("/")));
      

  2.   


    string str="test/c66c3ef8/c2623bd2/App_global.asax.hmet2dpt.0.cs";
    if(str.LastIndexOf("/")<0)
    {
      if(!Directory.Exists("~/test/c66c3ef8/c2623bd2/"))
      {
         Directory.CreateDirectory("~/test/c66c3ef8/c2623bd2/");
      }
    }
      

  3.   


    string urlPath=PrePath+"test/c66c3ef8/c2623bd2/App_global.asax.hmet2dpt.0.cs"; //PrePath为你的路径前缀
    System.IO.DirectoryInfo diBak = new System.IO.DirectoryInfo(urlPath);
       if (diBak.Exists)
       { return strPreXMLPath;}
       else
       {
         if(urlPath.EndWith(@"/"))
            {diBak.Create();}
         return diBak.FullName;
       }
      

  4.   

    改改:string str= "test/c66c3ef8/c2623bd2/App_global.asax.hmet2dpt.0.cs";
    if(str.LastIndexOf("/") != str.Length - 1)
         Directory.CreateDirectory(str.Substring(0, str.LastIndexOf("/")));