C#遍历文件夹及文件
来源:互联网 发布:centos snmp 安装配置 编辑:程序博客网 时间:2024/06/06 01:46
原文链接:http://www.cnblogs.com/hxh88/p/5814291.html
1、先判断目录是否存在
string strPath = Server.MapPath("/Files/txt");if (!Directory.Exists(strPath))//如果不存在就创建file文件夹{ Directory.CreateDirectory(strPath);}
Directory 类
原文来源:MSDN
下面的代码示例确定指定的目录是否存在,如果存在,则删除该目录;如果不存在,则创建该目录。 然后,此示例将移动此目录,在其中创建一个文件并对文件进行计数。
using System;using System.IO;class Test { public static void Main() { // Specify the directories you want to manipulate. string path = @"c:\MyDir"; string target = @"c:\TestDir"; try { // Determine whether the directory exists. if (!Directory.Exists(path)) { // Create the directory it does not exist. Directory.CreateDirectory(path); } if (Directory.Exists(target)) { // Delete the target to ensure it is not there. Directory.Delete(target, true); } // Move the directory. Directory.Move(path, target); // Create a file in the directory. File.CreateText(target + @"\myfile.txt"); // Count the files in the target directory. Console.WriteLine("The number of files in {0} is {1}", target, Directory.GetFiles(target).Length); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } finally {} }}
DirectoryInfo 类 (来源MSDN)
阅读全文
0 0
- C#遍历文件夹及文件
- C#遍历文件夹及文件
- C#遍历文件夹及文件
- C#遍历文件夹下的所有文件及文件夹
- C#遍历某个文件夹的文件及子文件夹
- 文件夹及子文件夹文件的遍历C#
- 文件夹及子文件夹文件的遍历C#
- 遍历文件及文件夹
- 遍历文件夹及文件
- 遍历文件及文件夹
- C#遍历整个文件夹及子目录的文件
- C#遍历整个文件夹及子目录的文件代码
- C#遍历文件夹中的文件
- python 遍历文件夹及文件
- 遍历文件夹中的所有文件夹及文件
- vc 遍历文件夹,删除文件及文件夹!
- C#磁盘类型判断 所有磁盘遍历出所有文件夹及文件夹路径 所有文件及文件路径
- C#遍历文件夹构造文件树
- pooling mean max 前向和反向传播
- Jave将数据导出成ecxel表格
- viewpager
- Ubuntu14.04虚拟机和宿主机(win7)之间的文件传输 (VMwareTools)篇 网上
- eclipse快捷键
- C#遍历文件夹及文件
- 【慕课网_性能优化之MySQL优化_学习】【09】
- Alwayson 同步模式的坑
- 关于oracle+ibatis批量insert的写法
- ElasticSearch 5.0及head插件安装
- cordova function link
- 利用ActionFilterAttribute监控----实现Controller监控
- 酸奶工厂
- Mybatis多参数传递