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]);
                
            }
            
        }
    }
  
} 
相关推荐
不当菜虚困几秒前
windows下HSDB导出class文件报错【java.io.IOException : 系统找不到指定的路径。】
java·开发语言
lsx2024063 分钟前
Vue.js 循环语句
开发语言
m0_561359673 分钟前
嵌入式C++加密库
开发语言·c++·算法
j4455661111 分钟前
C++中的职责链模式实战
开发语言·c++·算法
m0_6860416116 分钟前
实时数据流处理
开发语言·c++·算法
梵刹古音17 分钟前
【C语言】 字符型变量
c语言·开发语言·嵌入式
草履虫建模22 分钟前
A13 String 详解:不可变、常量池、equals 与 ==、性能与常见坑
java·开发语言·spring·jdk·intellij-idea·java基础·新手
知无不研28 分钟前
内存碎片与内存优化
开发语言·c++·内存优化·内存碎片·内存操作
invicinble29 分钟前
学习的门道和思路
java·开发语言·学习
m0_5613596731 分钟前
C++模块接口设计
开发语言·c++·算法