测速_C#创建文件夹代码

2008-06-30 VC 阅读:

///<summary>
    ///创建文件夹

     ///</summary>
    publicclass Util
    {
        [DllImport("msvcrt.dll", SetLastError =true, CharSet = CharSet.Unicode, ExactSpelling =true)]
        privatestaticexternint _mkdir(string path);

        ///<summary>
        /// 创建目录
        ///</summary>
        ///<param name="path"></param>
        ///<returns></returns>
        publicstatic DirectoryInfo CreateDirectory(string path)
        {
            DirectoryInfo oDir =new DirectoryInfo(Path.GetFullPath(path));

            try
            {
                if (!oDir.Exists)
                {
                    oDir.Create();
                }
                return oDir;
            }
            catch
            {
                CreateDirectoryUsingDll(oDir);
                returnnew DirectoryInfo(path);
            }
        }

        privatestaticvoid CreateDirectoryUsingDll(DirectoryInfo dir)
        {
            ArrayList oDirsToCreate =new ArrayList();

            while (dir !=null&&!dir.Exists)
            {
                oDirsToCreate.Add(dir.FullName);
                dir = dir.Parent;
            }

            if (dir ==null)
            {
                throw (new System.IO.DirectoryNotFoundException("Directory \"" + oDirsToCreate[oDirsToCreate.Count - 1] + "\" not found."));
            }

            for (int i = oDirsToCreate.Count -1; i >=0; i--)
            {
                string sPath = (string)oDirsToCreate[i];
                int iReturn = _mkdir(sPath);

                if (iReturn !=0)
                {
#if DEBUG
                    thrownew ApplicationException("Error calling [msvcrt.dll]:_wmkdir("+ sPath +"), error code: "+ iReturn);
#else
                    thrownew ApplicationException();
#endif
                }
            }
        }
    }

测速_C#创建文件夹代码

http://m.quanqiunao.cn/bianchengkaifa/4327/

推荐访问:藏宝阁 菜鸟教程 创客贴 草料二维码 cctv5 csdn cnki colg

VC推荐文章

推荐内容

上一篇:[刚装好windows]刚装好windows server 2003 就老是出现Generic Host Process错误 下一篇:vs2010密钥_VS2010 在哪些方面提高了开发的工作效率?