• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

C#创建文件夹代码

时间:2015年04月02日 15:41:09    来源:魔法猪系统重装大师官网    人气:12668

///


   
///创建文件夹

     ///


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

       
///
       
/// 创建目录
       
///

       
///
       
///
        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
                }
            }
        }
    }

创建,文件夹,代码,summary,创建,文件夹,publi
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部