方法如下:
/// <summary>
/// 給文件加後綴
/// </summary>
/// <param name="fi"></param>
/// <param name="suffix"></param>
void HoverTreeAddSuffix(FileInfo fi,string suffix)
{
string h_newFielName = fi.DirectoryName + "\\" + Regex.Replace(fi.Name, @"\" + fi.Extension + "$", "", RegexOptions.IgnoreCase) + suffix + fi.Extension;
fi.MoveTo(h_newFielName);
}
如果文件名為 何問起1.png 執行
HoverTreeAddSuffix(fi,"_hovertree");
之後,文件名就會變成:何問起1_hovertree.png
需要引用命名空間:
using System.Text.RegularExpressions;
using System.IO;