zoukankan      html  css  js  c++  java
  • 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;
            }
  • 相关阅读:
    2019 SDN上机第2次作业
    2019 SDN上机第1次作业
    第07组 团队Git现场编程实战
    第二次结对编程作业
    c语言之问题集
    2019春第2次课程设计实验安排
    2019年十二周总结
    第十一周总结
    第十周作业
    第九周总结
  • 原文地址:https://www.cnblogs.com/ylemzhang/p/1848120.html
Copyright © 2011-2022 走看看