/// <summary> /// 每次启动程序清理缓存 /// </summary> /// <param name="FloderPath"></param> public static void DeleteAllChildrenFile(String FloderPath) { foreach (string line in FloderHelper.GetFullFileNameList(FloderPath)) { FileHelper.FileDelete(line); } }
/// <summary> /// 覆盖源文件,写入text /// </summary> /// <param name="FilePath"></param> /// <param name="Content"></param> public static void WriteUTF8Text(String FilePath, string Content) { try { FloderHelper.FloderExits(FloderHelper.GetFloderPath(FilePath), true); File.WriteAllText(FilePath, Content, Encoding.UTF8); } catch (Exception ex) { PrintLog.Log(ex); } }
/// <summary> /// 移动文件夹文件到新文件夹 /// </summary> /// <param name="OldFloder"></param> /// <param name="NewFloder"></param> public static void FloderFileMove(string OldFloder, string NewFloder) { if (!FloderExits(NewFloder, true)) { Console.WriteLine("创建新文件夹失败"); return; } foreach (string line in FloderHelper.GetFullFileNameList(OldFloder)) { FileHelper.FileMove(line, Path.GetFullPath(NewFloder) + "\\" + Path.GetFileName(line)); } }
/// <summary> /// 下载帮助,快速创建文件夹初始化路径 /// </summary> /// <param name="FloderPath"></param> /// <param name="FileUrl"></param> /// <returns></returns> public static string FileDownNameHelper(string FloderPath, string FileUrl) { if (!FloderHelper.FloderExits(FloderPath, true)) { return(""); } FileUrl = FloderPath + Path.GetFileName(FileUrl); if (FileUrl.Length > 200)//文件名过长的情况进行溢出截断 { FileUrl = FloderPath + DateTime.Now.ToFileTime().ToString() + Path.GetExtension(FileUrl); } return(FileUrl); }
/// <summary> /// 移动文件 /// </summary> /// <param name="FilePath"></param> /// <param name="NewFilePath"></param> public static void FileMove(String FilePath, String NewFilePath) { try { FloderHelper.FloderExits(Path.GetDirectoryName(NewFilePath), true); if (File.Exists(NewFilePath)) { NewFilePath = FloderHelper.GetFloderPath(NewFilePath) + DateTime.Now.ToFileTime() + GetFileName(NewFilePath); } File.Move(FilePath, NewFilePath); } catch (Exception ex) { PrintLog.Log(ex); } }