软件编程
位置:首页>> 软件编程>> C#编程>> C#下实现创建和删除目录的实例代码

C#下实现创建和删除目录的实例代码

作者:shichen2014  发布时间:2021-10-21 16:04:31 

标签:C#,目录

本文所述代码是从一个C#程序中摘录出来的,主要实现C#创建目录、删除文件夹及文件的功能,包括所引用的名称空间等,特别是对C#不熟悉的初学者,会有一定的参考借鉴价值。下面把创建和删除文件夹的完整代码帖上来供大家参考借鉴。

代码入下所示:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace delete
{
 class Program
 {
   static void Main(string[] args)
   {
     deleteFiles(@"D:\Test\我的文件夹");
   }
   public static void deleteFiles(string strDir)
   {
     if (Directory.Exists(strDir))
     {
       Directory.Delete(strDir, true);
       Directory.CreateDirectory(strDir);
       Console.WriteLine("文件删除成功!");
       Console.ReadLine();
     }
     else
     {
       Directory.CreateDirectory(strDir);
       Console.WriteLine("文件夹创建成功!");
       Console.ReadLine();
     }
   }
 }
}

相信本文所述实例会对大家有一定的帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com