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]);
                
            }
            
        }
    }
  
} 
相关推荐
吴名氏.8 小时前
电子书《21天学通Java(第5版)》
java·开发语言·21天学通java
还是大剑师兰特8 小时前
C#面试题及详细答案120道(86-95)-- 进阶特性
c#·大剑师
星释8 小时前
Rust 练习册 :深入探索XOR加密与流密码
开发语言·网络·rust
郝学胜-神的一滴8 小时前
Effective STL 第9条:C++容器元素删除技巧详解
开发语言·c++·程序人生·stl
提娜米苏8 小时前
Bash Shell脚本学习——唇读数据集格式修复脚本
开发语言·学习·bash
larance9 小时前
python中的鸭子类型
开发语言·python
丙寅9 小时前
微信小程序反编译遇到 TypeError: _typeof3 is not a function
开发语言·javascript·ecmascript
醇氧9 小时前
MAC 安装openJDK8
java·开发语言
海阔天空在前走9 小时前
JAVA中六种策略模式的实现
java·开发语言·策略模式
青衫码上行9 小时前
【Java Web学习 | 第十篇】JavaScript(4) 对象
java·开发语言·前端·javascript·学习