C#下实现创建和删除目录的实例代码
作者:shichen2014 时间:2021-10-21 16:04:31
本文所述代码是从一个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();
}
}
}
}
相信本文所述实例会对大家有一定的帮助。
标签:C#,目录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
kill命令在Java应用中使用的注意事项小结
2023-11-11 13:01:55
![](https://img.aspxhome.com/file/2023/9/58889_0s.jpg)
java使用dom4j解析xml配置文件实现抽象工厂反射示例
2022-11-10 15:45:38
c#图片处理之图片裁剪成不规则图形
2023-02-23 02:43:58
![](https://img.aspxhome.com/file/2023/1/86981_0s.jpg)
c#.net多线程编程教学——线程同步
2021-12-27 06:03:50
如何使用C#操作幻灯片
2023-08-27 01:06:01
![](https://img.aspxhome.com/file/2023/5/111245_0s.jpg)
全面解析Hibernate关联操作、查询操作、高级特性、并发处理机制
2021-06-25 08:48:48
C#如何将Access中以时间段条件查询的数据添加到ListView中
2022-02-22 22:15:18
java实现学生成绩档案管理系统
2023-06-29 22:48:43
Java 按行读取文件按行写入文件并以空格分割字符串的方法
2023-08-31 12:32:21
java多线程读取多个文件的方法
2022-12-05 04:37:45
C# URL短地址压缩算法及短网址原理解析
2023-03-26 08:36:31
基于Tomcat7、Java、WebSocket的服务器推送聊天室实例
2023-11-25 23:35:34
![](https://img.aspxhome.com/file/2023/0/60390_0s.jpg)
Flutter 容器盒子模型的使用示例
2023-06-18 18:47:43
![](https://img.aspxhome.com/file/2023/4/85974_0s.png)
C#中的那些警告该如何去除(完全去除C#警告)
2023-09-07 20:55:53
![](https://img.aspxhome.com/file/2023/1/76381_0s.png)
关于weblogic部署Java项目的包冲突问题的解决
2023-07-19 19:02:59
![](https://img.aspxhome.com/file/2023/4/96524_0s.png)
Java 给PDF签名时添加可信时间戳的方法
2022-04-03 12:38:48
![](https://img.aspxhome.com/file/2023/9/96129_0s.png)
springboot2.X整合prometheus监控的实例讲解
2021-07-04 13:49:59
![](https://img.aspxhome.com/file/2023/2/82442_0s.jpg)
IntelliJ IDEA 2022.2 正式发布新功能体验
2021-08-14 02:47:33
![](https://img.aspxhome.com/file/2023/7/95947_0s.png)
C#通过rabbitmq实现定时任务(延时队列)
2021-11-02 23:11:17
![](https://img.aspxhome.com/file/2023/6/87056_0s.png)
Spark网站日志过滤分析实例讲解
2021-06-08 12:59:24
![](https://img.aspxhome.com/file/2023/7/60927_0s.png)