一、创建文件夹,例:

  if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

二、创建文件,例:

  global::System.IO.FileInfo josnfile = new global::System.IO.FileInfo(JsonPath);
if (!josnfile.Exists)
{
// 创建map.json文件
FileStream fs = new FileStream(JsonPath, FileMode.CreateNew, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write("[]");
sw.Flush();
sw.Close();
//Thread.Sleep(300);
}

三、遍历文件夹下的所有文件或文件夹

遍历文件:

//录像文件
string videoPath = fileManager.TrimEnd('\\') + "\\" + item.CourtID + "\\Conference\\" + item.ID;
if(Directory.Exists(videoPath))
{
  DirectoryInfo TheFolder = new DirectoryInfo(videoPath);
  //遍历文件
  foreach (global::System.IO.FileInfo NextFile in TheFolder.GetFiles())
{
}
}

遍历文件夹:

if(Directory.Exists(videoPath))
{
  DirectoryInfo TheFolder=new DirectoryInfo(videoPath);
  //遍历文件夹
  foreach(DirectoryInfo NextFolder in TheFolder.GetDirectories())
  {
  }
}

四、读取文件内容,例:

                 using (FileStream fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312")))
{
noteIsSubmit = sr.ReadToEnd().ToString().Contains(FileName);
}
}

五、复制文件,例:

  global::System.IO.FileInfo _f = new global::System.IO.FileInfo(path);
try
{
if (!_f.Exists)
{
//复制讲稿文件
global::System.IO.FileInfo copyFile = new global::System.IO.FileInfo(FileURL);
copyFile.CopyTo(path);
}
}
catch (Exception ex)
{
Logger.D("NoteMake讲稿制作发生异常:", ex.Message);
}

六、删除指定文件,例:

string path = FileManager.BASEPATH + "\\" + item.CourtID + "\\Topics\\" + item.ID + "\\" + item.Type + ".doc";
global::System.IO.FileInfo _f = new global::System.IO.FileInfo(path);
if (_f.Exists)
{
global::System.IO.File.Delete(path);
}

七、删除指定文件夹,例:

//讲稿标注文档路径
string noteFilePath = item.FilePath.Substring(, item.FilePath.LastIndexOf('.'));
if (Directory.Exists(noteFilePath))
{
DirectoryInfo _d = new DirectoryInfo(noteFilePath);
_d.Delete(true);//删除子目录和文件
}

最新文章

  1. jQuery的页面载入
  2. Distributed MVCC based cross-row transaction
  3. 全文搜索 Lucene.Net
  4. 在springmvc中配置jedis:
  5. 数迹学——Asp.Net MVC4入门指南(2):添加一个控制器
  6. System.exit(1)
  7. ToDoList:一款非常优秀的任务管理软件 —— 工具类
  8. Android配置----小米手机通过wifi连接ADB调试Android应用
  9. C#访问PostGreSQL数据库的方法 http://www.jb51.net/article/35643.htm
  10. STM32内存跟FLASH问题
  11. 将项目初始化到git服务器
  12. hdu 4143 A Simple Problem (变形)
  13. 真实代理(RealProxy)在WCF中的运用
  14. 58、js扩展
  15. linux dialog详解(图形化shell)
  16. 查看linux系统是运行在物理机还是虚拟机方法
  17. Pre-shared key
  18. Xcode 插件优缺点对照(推荐 20 款插件)
  19. 使用golang编写prometheus metrics exporter
  20. 测试教程网.unittest教程.3. 实例: 测试弱密码

热门文章

  1. Eureka服务注册过程详解之IpAddress(详解eureka.instance.prefer-ip-address = true 与 eureka.instance.prefer-ip-address)
  2. 最新的ES 5.0路由算法底层实现
  3. mysql日常运维
  4. hibernate多对一和一对多关联
  5. 了解SAGA
  6. 20165202 Mypwd
  7. Kali Linux更新源以及设置中文
  8. block ,GCD(转)
  9. tomcat部署和启动
  10. Flume-NG源码阅读之SpoolDirectorySource(原创)