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]);
                
            }
            
        }
    }
  
} 
相关推荐
He19550117 分钟前
wordpress搭建块
开发语言·wordpress·古腾堡·wordpress块
老天文学家了41 分钟前
蓝桥杯备战Python
开发语言·python
赫瑞44 分钟前
数据结构中的排列组合 —— Java实现
java·开发语言·数据结构
初夏睡觉1 小时前
c++1.3(变量与常量,简单数学运算详解),草稿公放
开发语言·c++
升职佳兴1 小时前
C盘爆满自救:3步无损迁移应用数据到E盘(含回滚)
c语言·开发语言
ID_180079054731 小时前
除了 Python,还有哪些语言可以解析 JSON 数据?
开发语言·python·json
周末也要写八哥2 小时前
多进程和多线程的特点和区别
java·开发语言·jvm
宁瑶琴3 小时前
COBOL语言的云计算
开发语言·后端·golang
小陈工4 小时前
2026年4月2日技术资讯洞察:数据库融合革命、端侧AI突破与脑机接口产业化
开发语言·前端·数据库·人工智能·python·安全
Zarek枫煜4 小时前
C3 编程语言 - 现代 C 的进化之选
c语言·开发语言·青少年编程·rust·游戏引擎