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]);
                
            }
            
        }
    }
  
} 
相关推荐
q***d17311 小时前
Kotlin在后台服务中的框架
android·开发语言·kotlin
周杰伦fans11 小时前
C# 中的 `Hashtable`
开发语言·c#
习习.y11 小时前
关于python中的面向对象
开发语言·python
lingggggaaaa11 小时前
免杀对抗——C2远控篇&PowerShell&有无文件落地&C#参数调用&绕AMSI&ETW&去混淆特征
c语言·开发语言·笔记·学习·安全·microsoft·c#
技术净胜11 小时前
MATLAB 基因表达数据处理与可视化全流程案例
开发语言·matlab
友友马11 小时前
『Qt』多元素控件
开发语言·qt
hmbbcsm11 小时前
练习python题目小记(六)
开发语言·python
4***V20212 小时前
Vue3响应式原理详解
开发语言·javascript·ecmascript
q***985212 小时前
VS Code 中如何运行Java SpringBoot的项目
java·开发语言·spring boot
共享家952712 小时前
QT-界面优化(中)
开发语言·qt