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]);
                
            }
            
        }
    }
  
} 
相关推荐
FAFU_kyp29 分钟前
Rust 模式匹配:match 与 if let 详解
开发语言·后端·rust
星火开发设计1 小时前
C++ 运算符全解析:算术、关系、逻辑与位运算
java·开发语言·c++·学习·位运算·知识·操作符
AI_56781 小时前
Postman接口测试极速入门指南
开发语言·人工智能·学习·测试工具·lua
Emilin Amy1 小时前
【C++】【STL算法】那些STL算法替代的循环
开发语言·c++·算法·ros1/2
遇印记1 小时前
蓝桥java求最大公约数
java·开发语言
ONExiaobaijs1 小时前
【无标题】
java·开发语言·spring·maven·程序员创富
IMPYLH1 小时前
Lua 的 String(字符串) 模块
开发语言·笔记·单元测试·lua
符哥20081 小时前
Mybatis和Mybatis-plus区别
java·开发语言·mybatis
企业对冲系统官1 小时前
期货与期权一体化平台风险收益评估方法与模型实现
运维·服务器·开发语言·数据库·python·自动化
ceclar1232 小时前
C++使用numeric
开发语言·c++