批量改文件名软件保留每次过滤扩展名

批量改文件名软件保留每次过滤扩展名,这样就不必每次都要手动新选择设置。

public class ConfigInfo
{
    public List Extenstions { set; get; }

    public ConfigInfo()
    {
        Extenstions = new List();
    }
}

 private static ConfigInfo getConfigInfo()
 {
     string json = Common.ConfigLord.GetConfig(new ConfigInfo().ToString());
     ConfigInfo configInfo;
     try
     {
         if (json == "") configInfo = new ConfigInfo();
         else configInfo = JsonConvert.DeserializeObject(json);
     }
     catch
     {
         configInfo = new ConfigInfo();
     }
     return configInfo;
 }

 private bool setConfigInfo()
 {
     ConfigInfo configInfo = new ConfigInfo();
     configInfo.Extenstions = _extensions;
     string json = JsonConvert.SerializeObject(configInfo);
     Spirit.Common.ConfigLord.SetConfig(configInfo.ToString(), json);
     return true;
 }

      private void btnOK_Click(object sender, EventArgs e)
      {
          _extensions.Clear();
          foreach (ListViewItem lvItem in lvExtensions.Items)
          {
              if (lvItem.Checked)
                  _extensions.Add(lvItem.Text);
          }
          if (_extensions.Count == 0)
          {
              MessageBox.Show("请至少选中一个文件扩展名称。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
              return;
          }
          NewDataTable = _dataTable.Clone();
          setConfigInfo();
          foreach (DataRow dr in _dataTable.Rows)
          {
              string fileName = dr["FileName"].ToString();
              string extention = Path.GetExtension(fileName).ToLower().Trim();
              if (_extensions.Contains(extention))
                  NewDataTable.ImportRow(dr);
          }
          DialogResult = DialogResult.OK;
      }

 private void FrmFilter_Load(object sender, EventArgs e)
 {
     lvExtensions.CheckBoxes = true;
     lvExtensions.SmallImageList = new ImageList();
     lvExtensions.SmallImageList.ImageSize = new Size(16, 16);
     lvExtensions.SmallImageList.ColorDepth = ColorDepth.Depth32Bit;
     lvExtensions.LargeImageList = new ImageList();
     lvExtensions.FullRowSelect = true;
     lvExtensions.HideSelection = false;
     lvExtensions.View = View.Details;

     _iconImageProvider = new IconImageProvider(lvExtensions.SmallImageList, lvExtensions.LargeImageList);
     ColumnHeader ch = new ColumnHeader();
     ch.Width = lvExtensions.Width - 5;

     ch.Text = "扩展名称(后缀名称)";
     lvExtensions.Columns.Add(ch);
     List list = new List();
     Dictionary dic = new Dictionary();
     foreach (DataRow dr in _dataTable.Rows)
     {
         string fileName = dr["FileName"].ToString();
         string extention = Path.GetExtension(fileName).ToLower().Trim();
         string path = dr["Path"].ToString();
         if (!dic.ContainsKey(extention))
         {
             list.Add(extention);
             dic.Add(extention, path);
         }
     }
     string[] arr = list.ToArray();
     Array.Sort(arr);
     ConfigInfo configInfo = getConfigInfo();
     foreach (string extention in arr)
     {
         ListViewItem lvItem = new ListViewItem();
         lvItem.ImageIndex = _iconImageProvider.GetIconImageIndex(dic[extention]);
         lvItem.Text = extention;
         if (configInfo.Extenstions.Contains(extention))
             lvItem.Checked = true;
         else
             lvItem.Checked = false;
         lvExtensions.Items.Add(lvItem);
     }
 }
批量修改文件名 2024年最新版 完全免费
批量修改文件名称、文件夹名称

方便快捷,支持正则表达式、无需安装功能齐全、支持定制无广告、无插件,放心使用。

免费下载 百度网盘
本站中所有的计算器的计算结果仅供参考,本站对此结果的准确性不承担任何责任,实际数额以银行/保险公司/国家相关机构确认的结果为准。
在线客服QQ:543690914,备案号: 苏ICP备15037649号-33。东海县白塔埠镇佳诚电脑经营部版权所有。