zoukankan      html  css  js  c++  java
  • 某个文件下下面的文件批量改名

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;

    namespace ChangeFileName
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    FolderBrowserDialog fbd = new FolderBrowserDialog();

    if (fbd.ShowDialog() == DialogResult.OK)
    {
    textBox1.Text = fbd.SelectedPath;
    }
    }

    /// <summary>
    /// 递归算法
    /// </summary>
    /// <param name="strBaseDir"></param>
    public void GetAllDirList(string strBaseDir)
    {
    DirectoryInfo di = new DirectoryInfo(strBaseDir);
    DirectoryInfo[] diA = di.GetDirectories();
    for (int i = 0; i < diA.Length; i++)
    {
    string dfileName = System.IO.Path.ChangeExtension(diA[i].FullName, ".sql");
    File.Move(diA[i].FullName, dfileName);
    GetAllDirList(diA[i].FullName);
    //注意:递归了。
    }
    }

    private void button2_Click(object sender, EventArgs e)
    {
    DirectoryInfo d = new DirectoryInfo(textBox1.Text);
    GetAll(d);
    MessageBox.Show("操作完成");
    }

    void GetAll(DirectoryInfo dir)//搜索文件夹中的文件
    {

    FileInfo[] allFile = dir.GetFiles();
    foreach (FileInfo fi in allFile)
    {
    var fileName = fi.Name;
    var houzui = "";
    if (radioButton1.Checked)
    {
    houzui = fileName.Substring(fileName.LastIndexOf(".") + 1) + textBox2.Text.Trim();
    }
    else if (radioButton2.Checked)
    {
    houzui = fileName.Substring(fileName.LastIndexOf(".") + 1);
    houzui=houzui.Replace(textBox2.Text.Trim(), "");
    }
    else if (radioButton3.Checked)
    {
    houzui =textBox2.Text;
    }
    string dfileName = System.IO.Path.ChangeExtension(fi.FullName, houzui);
    File.Move(fi.FullName, dfileName);
    }

    DirectoryInfo[] allDir = dir.GetDirectories();
    foreach (DirectoryInfo d in allDir)
    {
    GetAll(d);
    }
    }
    }
    }

  • 相关阅读:
    从zk监控canal-client消费延迟情况
    python面向对象——类的参数
    python面向对象——类的继承
    python并发——进程间同步和通信(二)
    python并发——线程池与进程池(转)
    python从指定目录排除部分子目录——用于删除目录
    python并发统计s3目录大小
    Java对象的序列化和反序列化
    多态、抽象类和接口
    Java输入输出流
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/5254371.html
Copyright © 2011-2022 走看看