Fork me on GitHub

文件夹内修改文件名称

using System;
using System.IO;
namespace UsefulFunctions.Functions
{
    public class ReviseFileNames
    {
        public void ReviseFileName(string addr1,string addr2)
        { 
            var path = Directory.GetFiles(addr1);

            foreach (var str in path)
            { 
                var file = new FileInfo(str);
                var f = file.Name.Substring(0, file.Name.LastIndexOf(".dwg", StringComparison.Ordinal));

                if (!Directory.Exists(addr2))
                {
                    Directory.CreateDirectory(addr2);
                }
                var p = addr2 + f + "S.dwg" + file.Extension;
                file.MoveTo(p);
            }
        }
    }
}

 

posted @ 2016-04-08 12:36  千秋此意  阅读(179)  评论(0编辑  收藏  举报