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]);
                
            }
            
        }
    }
  
} 
相关推荐
清风与日月3 分钟前
c# 集成激光雷达(以思岚A1为例)
开发语言·c#
是苏浙18 分钟前
零基础入门C语言之贪吃蛇的实现
c语言·开发语言·数据结构
化作星辰36 分钟前
java 给鉴权kafka2.7(sasl)发送消息权限异常处理
java·大数据·开发语言·kafka
无极小卒36 分钟前
如何在三维空间中生成任意方向的矩形内部点位坐标
开发语言·算法·c#
克里斯蒂亚诺更新40 分钟前
微信小程序 点击某个marker改变其大小
开发语言·前端·javascript
Alberta ゙2 小时前
C++初阶
开发语言·c++
the白勺2 小时前
RabbitMQ-基础-总结
开发语言·c#
Dev7z2 小时前
基于Matlab多目标粒子群优化的无人机三维路径规划与避障研究
开发语言·matlab·无人机
沐知全栈开发3 小时前
HTML 脚本:基础、应用与未来趋势
开发语言
@菜菜_达3 小时前
interact.js 前端拖拽插件
开发语言·前端·javascript