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]);
                
            }
            
        }
    }
  
} 
相关推荐
普通网友1 分钟前
C++中的适配器模式
开发语言·c++·算法
风闲12173 分钟前
Qt源码编译记录
开发语言·qt
普通网友23 分钟前
C++中的委托构造函数
开发语言·c++·算法
月上柳青38 分钟前
OpenWrt系统上配置batman-adv快速开始与配置详解
开发语言·mysql·php
全栈陈序员39 分钟前
基于Rust 实现的豆瓣电影 Top250 爬虫项目
开发语言·爬虫·rust
普通网友39 分钟前
C++中的代理模式实战
开发语言·c++·算法
百锦再44 分钟前
第17章 模式与匹配
开发语言·后端·python·rust·django·内存·抽象
WangMing_X1 小时前
C# XML操作演示示例项目(附源码完整)
开发语言·microsoft·php
Charles_go1 小时前
C#中级1、元祖和值元组有什么区别
c#
普通网友1 小时前
C++模块化设计原则
开发语言·c++·算法