首页 > Windows开发 > 详细

C# 文件/文件夹重命名

时间:2015-10-31 12:51:07      阅读:260      评论:0      收藏:0      [点我收藏+]

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下载地址

C# 文件/文件夹重命名

原文:http://www.cnblogs.com/bindot/p/rename.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!