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]);
                
            }
            
        }
    }
  
} 
相关推荐
gc_22994 分钟前
C#学习调用OpenMcdf模块解析ole数据的基本用法(2)
c#·ole·openmcdf·offvis软件
浅念-9 分钟前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
lly20240614 分钟前
Docker 安装 Python
开发语言
bugcome_com17 分钟前
C# 变量详解(从入门到掌握)
c#
道法自然|~22 分钟前
BugkuCTF栅栏密码解题记录(原理+C语言实现)
c语言·开发语言
kylezhao201930 分钟前
C#中如何防止序列化文件丢失和损坏
c#
CircleMouse1 小时前
springboot项目中使用Java 8的日期时间API
java·开发语言·spring boot·后端·spring
玩c#的小杜同学1 小时前
工业级稳定性:如何利用生产者-消费者模型(BlockingCollection)解决串口/网口高频丢包问题?
笔记·学习·性能优化·c#·软件工程
前端达人1 小时前
被JavaScript忽视的Web Animations API:为什么说它是前端动画的真正未来?
开发语言·前端·javascript·ecmascript