CANoe等工程文件夹批量化建立工具

10 篇文章 0 订阅
1、工具制作原因

        个人在工作经历中,需要频繁建立文件夹,就设计一个配置文件夹建立工具,为了方便平时自己快速建立文件夹。然后后期方便自己能够再增加其他管控文件夹,并且使用自己的工具集合在一起,方便使用。

2、实现UI

3、配置文件

使用ini文件配置你需要批量生成的文件夹,并且做到可以配置修改。

4、实现代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace CANoeHelperTool
{
    public partial class FileBatchCreationAccordingToRules : Form
    {
        public FileBatchCreationAccordingToRules()
        {
            InitializeComponent();
            iniFile = new IniFile();
        }

        private string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
        private IniFile iniFile;
        private List<string> ListPathFile;


        private void bt_ReadIni_Click(object sender, EventArgs e)
        {
            ListPathFile = new List<string>();
            iniFile.LoadFile(baseDirectory + textBox_FileIni.Text);
            GetCANoeTemplate();
        }

        private void GetCANoeTemplate()
        {
            textBox_FileName.Text = iniFile.GetValue(comboBox_ReadIni.Text, "FileName");
            ListPathFile = GetListPath(comboBox_ReadIni.Text, "File");
            if (ListPathFile == null)
            {
                return;
            }
            listBoxFilePath.Items.Clear();
            foreach (string item in ListPathFile)
            {
                listBoxFilePath.Items.Add(item);
            }
        }


        private void bt_OutputPath_Click(object sender, EventArgs e)
        {
            listBoxLog.Items.Clear();
            if (NewFile(textBox_OutFilepath.Text + "\\" + textBox_FileName.Text, ListPathFile))
            {
                listBoxLog.Items.Add(textBox_OutFilepath.Text + "\\" + textBox_FileName.Text + "   文件夹输出成功");
            }
            else
            {
                listBoxLog.Items.Add(textBox_OutFilepath.Text + "\\" + textBox_FileName.Text + "   文件夹输出失败");
            }
        }

        private bool NewFile(string basePath, List<string> ListPathFile)
        {
            try
            {
                foreach (string folderName in ListPathFile)
                {
                    string folderPath = basePath + folderName;

                    // 检查文件夹是否已经存在
                    if (!Directory.Exists(folderPath))
                    {
                        // 如果不存在,则创建新的文件夹
                        Directory.CreateDirectory(folderPath);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        private void bt_Open_Click(object sender, EventArgs e)
        {
            OpenFolder(textBox_OutFilepath.Text + "\\" + textBox_FileName.Text);
        }

        private void OpenFolder(string folderPath)
        {
            try
            {
                Process.Start(folderPath);
                listBoxLog.Items.Add("OpenFolder OK");
            }
            catch (Exception ex)
            {
                listBoxLog.Items.Add("An error occurred: " + ex.Message);
            }
        }
5、后记

        简单分享希望对你有用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值