c#文件,目录重命名

/// <summary>
        /// 文件重命名
        /// </summary>
        /// <param name="fInfo"></param>
        /// <param name="newPath"></param>
        public static bool RenameFile(FileInfo fInfo,string newPath)
        {
            string fullName = String.Format(LOG_FULLNAME, "RenameFile");
            Dictionary<string, string> logDic = new Dictionary<string, string>();
            logDic.Add("newPath", newPath);
            LogMessageHelper.LogerMessage(LogMessageLevel.Info, fullName, string.Empty, "文件重命名", logDic);            
            try
            {
                fInfo.MoveTo(newPath);
            }
            catch (Exception ex)
            {
                LogMessageHelper.LogerMessage(LogMessageLevel.Error, fullName, string.Empty, "文件重命名错误", logDic, ex);
                return false;
            }
            return true;
        }

        /// <summary>
        /// 目录重命名
        /// </summary>
        /// <param name="fInfo"></param>
        /// <param name="newPath"></param>
        public static bool RenameDir(DirectoryInfo di, string newPath)
        {
            string fullName = String.Format(LOG_FULLNAME, "RenameDir");
            Dictionary<string, string> logDic = new Dictionary<string, string>();
            logDic.Add("newPath", newPath);
            LogMessageHelper.LogerMessage(LogMessageLevel.Info, fullName, string.Empty, "目录重命名", logDic);
            try
            {
                di.MoveTo(newPath);
            }
            catch (Exception ex)
            {
                LogMessageHelper.LogerMessage(LogMessageLevel.Error, fullName, string.Empty, "目录重命名错误", logDic, ex);
                return false;
            }
            return true;
        }
原文地址:https://www.cnblogs.com/ylemzhang/p/1848120.html