• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#文件/文件夹重命名

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

C# 重命名的方法是MoveTo()

官方文档地址 (https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo.moveto%28VS.80%29.aspx)

另附上Demo部分代码:

 private void btn_start_Click(object sender, EventArgs e)
        {
            //找到目录
            DirectoryInfo directoryinfo = new DirectoryInfo(txt_path.Text);
            int i = 1;
            //读取当前目录文件信息
            foreach (var item in directoryinfo.GetFiles())
            {
              
                string destPath = Path.Combine(txt_path.Text, i + item.Extension);
                if (item.Name.Length > 10)
                {
  //判断是否重名
                    if (!File.Exists(destPath))
                    {
                        item.MoveTo(destPath);
                    } i
++; } } MessageBox.Show("操作完成"); //通过长宽新建文件夹 //将该尺寸的文件移动到文件夹下并重命名 } private void txt_path_Click(object sender, EventArgs e) { DialogResult dr = folderBrowserDialog1.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { txt_path.Text = folderBrowserDialog1.SelectedPath; } }

 

界面:

 

附Demo下载地址


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]在WinForm中通过C#调用CHM帮助文件发布时间:2022-07-13
下一篇:
[翻译]扩展C#中的异步方法发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap