• 大小: 66KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-17
  • 语言: 其他
  • 标签:

资源简介

这是一个新型的批量重命名文件工具软件源码,主要用了TreeView(树形视图)来选择文件夹,批量进行文件重命名。其中,有"编号在前,编号在后,扩展名重命名"。其中有一个新的,是对Word的标题的批量处理。注释很详细...

注意:
开发环境为Visual Studio 2010

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using Word = Microsoft.Office.Interop.Word;

namespace BatchRenameFilesWithTreeView {
    public partial class Form1: Form {
        public Form1() {
            InitializeComponent();
            //取消.
            btnCancel.Click += (sender e) => { this.Dispose(); };
        }

        //初始加载树目录.
        void InitializeTreeView(TreeNode tNode) {
            if(tNode == null || tNode.Nodes == null) return;   //空节点或终结点.
            if(tNode.Nodes.Count != 0) return;  //已经添加节点.
            if(tNode.Parent == null) {  //根节点.
                foreach(var driver in Directory.GetLogicalDrives()) {   //盘符.
                    TreeNode driNode = new TreeNode(driver);
                    tNode.Nodes.Add(driNode);
                }
            }
            else {
                if(Directory.Exists(tNode.Text)) {  //为文件夹.
                    foreach(var dir in Directory.GetFileSystemEntries(tNode.Text)) {
                        tNode.Nodes.Add(new TreeNode(dir));
                    }
                }
            }
        }

        private void Form1_Load(object sender EventArgs e) {
            TreeNode rootNode = new TreeNode(“我的电脑“);   //添加根目录.
            tvFiles.Nodes.Add(rootNode);

            rabtn_Id.Checked = true;   //初始时选择编号.
            combox_Extension.SelectedIndex = 0; //默认选择第一项. 
        }
        //显示子节点.
        private void tvFiles_AfterSelect(object sender TreeViewEventArgs e) {
            InitializeTreeView(e.Node);
        }

        //按编号重命名选择改变. 
        private void rabtn_Id_CheckedChanged(object sender EventArgs e) {
            if(rabtn_Id.Checked) {
                rabtn_IdStart.Enabled = rabtn_IdEnd.Enabled = true;
                rabtn_IdStart.Checked = true; //默认为在文件名前面加编号.
                combox_Extension.Enabled = txtOri.Enabled = txtNew.Enabled = false;
            }
            else
                rabtn_IdStart.Enabled = rabtn_IdEnd.Enabled = false;
        }

        //按扩展名选择改变.
        private void rabtn_Extension_CheckedChanged(object sender EventArgs e) {
            if(rabtn_Extension.Checked) {
                combox_Extension.Enabled = true;
                rabtn_IdStart.Enabled = rabtn_IdEnd.Enabled = false;
            }
            else
                combox_Extension.Enabled = false;
        }

        //批量替换文件标题中的文字选择改变.
        private void rabtn_title_CheckedChanged(object sender EventArgs e) {
            if(rabtn_title.Checked) {
                txtOri.Enabled = txtNew.Enabled = true;
                rabtn_IdStart.Enabled = rabtn_IdEnd.Enabled = combox_Extension.Enabled = false;
            }
            else
                txtOri.Enabled = txtNew.Enabled = false;
        }
        //选择.

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3980  2013-07-11 12:50  BatchRenameFiles_1.0\BatchRenameFilesWithTreeView.csproj

     文件       1001  2013-07-15 08:33  BatchRenameFiles_1.0\BatchRenameFilesWithTreeView.sln

     文件      25600  2013-07-12 17:01  BatchRenameFiles_1.0\bin\Debug\BatchRenameFilesWithTreeView.exe

     文件      46592  2013-07-12 17:01  BatchRenameFiles_1.0\bin\Debug\BatchRenameFilesWithTreeView.pdb

     文件      11600  2013-07-15 08:37  BatchRenameFiles_1.0\bin\Debug\BatchRenameFilesWithTreeView.vshost.exe

     文件        490  2012-06-02 22:34  BatchRenameFiles_1.0\bin\Debug\BatchRenameFilesWithTreeView.vshost.exe.manifest

     文件      12506  2013-07-11 17:24  BatchRenameFiles_1.0\Form1.cs

     文件      17613  2013-07-11 11:31  BatchRenameFiles_1.0\Form1.Designer.cs

     文件       5817  2013-07-11 11:31  BatchRenameFiles_1.0\Form1.resx

     文件       2820  2013-07-15 08:37  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.csproj.FileListAbsolute.txt

     文件        975  2013-07-11 11:31  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.csproj.GenerateResource.Cache

     文件       9880  2013-07-11 17:15  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.csprojResolveAssemblyReference.cache

     文件      25600  2013-07-12 17:01  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.exe

     文件        180  2013-07-11 12:50  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.Form1.resources

     文件      46592  2013-07-12 17:01  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.pdb

     文件        180  2013-07-11 12:50  BatchRenameFiles_1.0\obj\x86\Debug\BatchRenameFilesWithTreeView.Properties.Resources.resources

     文件       5359  2013-07-11 00:11  BatchRenameFiles_1.0\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6816  2013-07-15 08:33  BatchRenameFiles_1.0\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        614  2013-07-10 17:04  BatchRenameFiles_1.0\OwnDirectory.cs

     文件        505  2013-07-10 15:46  BatchRenameFiles_1.0\Program.cs

     文件       1486  2013-07-10 15:46  BatchRenameFiles_1.0\Properties\AssemblyInfo.cs

     文件       2796  2013-07-10 15:46  BatchRenameFiles_1.0\Properties\Resources.Designer.cs

     文件       5612  2013-07-10 15:46  BatchRenameFiles_1.0\Properties\Resources.resx

     文件       1086  2013-07-10 15:46  BatchRenameFiles_1.0\Properties\Settings.Designer.cs

     文件        249  2013-07-10 15:46  BatchRenameFiles_1.0\Properties\Settings.settings

     文件        287  2013-11-19 09:36  BatchRenameFiles_1.0\源码必读.txt

    ..AD...         0  2013-07-15 08:40  BatchRenameFiles_1.0\obj\x86\Debug\TempPE

     目录          0  2013-07-12 17:01  BatchRenameFiles_1.0\obj\x86\Debug

     目录          0  2013-07-12 17:00  BatchRenameFiles_1.0\bin\Debug

     目录          0  2013-07-10 15:46  BatchRenameFiles_1.0\obj\x86

............此处省略7个文件信息

评论

共有 条评论