c#遍历文件重命名

参考

https://blog.csdn.net/qq_42607586/article/details/131080456

https://www.techiedelight.com/zh/delete-file-in-csharp/

https://it.cha138.com/python/show-2350967.html

https://www.zadmei.com/rhzczzmm.html

csharp 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string oldPath = "F:\\www\\a\\img\\33\\";
            string[] le = System.IO.Directory.GetFiles(@"F:\\www\\a\\img\\33");
            int i = le.Length;
            //Console.WriteLine(System.IO.Directory.GetFiles(@"F:\\www\\a\\img\\166").Length);
            Console.WriteLine(le[0]);//获取文件名
            Console.WriteLine(le.Length);//获取文件名
            for (int c = 0; c < i; c++) {
                Console.WriteLine(le[c]);//获取文件名
                string oldFilename = Path.GetFileNameWithoutExtension(le[c]);//"4"
                Console.WriteLine(oldFilename+"旧");//获取文件名
                string newname=oldPath+c.ToString()+".jpg";
                Console.WriteLine(newname+"新");//获取文件名
                File.Copy(le[c], newname,true);
                File.Delete(le[c]);
                
            }
            
        }
    }
  
} 
相关推荐
白露与泡影7 分钟前
阿里一面:Nacos配置中心交互模型是 push 还是 pull ?(原理+源码分析)
开发语言·php·交互
techdashen8 分钟前
性能比拼: Node.js vs Go
开发语言·golang·node.js
十碗阳春面9 分钟前
MATLAB 中文注释乱码的问题
开发语言·matlab
aiden:)39 分钟前
设计模式之工厂模式(factory pattern):在商品对象创建系统中的应用
java·开发语言·设计模式·软件工程·软件构建
Tdm_88843 分钟前
SQL Server中OPENJSON + WITH 来解析JSON
java·数据库·sql·c#·json·mssql
C137的本贾尼1 小时前
Java内部类详解
java·开发语言
Linux编程用C1 小时前
rust编程学习(二):复合数据类型
开发语言·学习·rust
末央&1 小时前
【C++】Stack和Queue的底层封装和实现
开发语言·c++
CrabKA1 小时前
Go-zero:JWT鉴权方式
开发语言·后端·golang
martian6651 小时前
C++异步编程从入门到精通实战:全面指南与实战案例
开发语言·c++·性能优化