zoukankan      html  css  js  c++  java
  • 小程序-批量修改不规范文件名

    一堆文件夹里有一堆文件,这些文件的名字包含了#等特殊字段,通过这个方法可以将这些文件命名统一更改

    注:红色区域可以修改为对文件的逻辑处理

    public void listDirectory (string path,char putChar)

    {

      DorectoryInfo theFolder=new DirectoryInfo(path)  //文件夹路径

    //遍历文件

      foreach(FileInfo nextFile in theFolder.GetFiles()){

        string filename = NextFile.FullName;//文件名

        if(filename.Contains(putChar)){//是否包含该字符

          string newFileName=filename;

          newFileName=newFileName.Replace(putChar,'x')//将违规字符改为其它字符,也可以作为参数传进来

          NextFile.MoveTo(newFileName);//移动文件到该目录下

        }

      }

    //遍历文件夹

      foreach(DirectoryInfo newFolder in theFolder.GetDirectories())

      {

         listDirectory(newFolder.FullName,putChar);//递归处理

      }

    }

    文件处理一直是麻烦的事情,特别是txt文件导入数据或者shape文件导入数据。如果院里大神有多线程处理方法希望我们可以交流一下。

  • 相关阅读:
    [湖南集训]谈笑风生
    【SCOI2010】序列操作
    ●BZOJ 3994 [SDOI2015]约数个数和
    ●BZOJ 3309 DZY Loves Math
    ●UOJ 21 缩进优化
    ●BZOJ 2693 jzptab
    ●BZOJ 2154 Crash的数字表格
    ●BZOJ 3529 [Sdoi2014]数表
    ●2301 [HAOI2011] Problem b
    ●BZOJ 2820 YY的GCD
  • 原文地址:https://www.cnblogs.com/newrohlzy/p/8922421.html
Copyright © 2011-2022 走看看