schangxiang@126.com
2025-05-16 dcad42e7c00871e816e4196732aead7cb7c560c2
//是否要事先清理文件夹
已添加1个文件
已修改3个文件
102 ■■■■■ 文件已修改
Weben_CMS专用代码生成器/Code/GenerateCode_WeiBen_CMS.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Weben_CMS专用代码生成器/Code/MainForm.Designer.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Weben_CMS专用代码生成器/Code/MainForm.cs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Weben_CMS专用代码生成器/Code/Utility/FileHelper.cs 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Weben_CMSרÓôúÂëÉú³ÉÆ÷/Code/GenerateCode_WeiBen_CMS.csproj
@@ -273,6 +273,7 @@
      <DependentUpon>MainForm.cs</DependentUpon>
    </Compile>
    <Compile Include="Utility\StructStrHelper.cs" />
    <Compile Include="Utility\FileHelper.cs" />
    <Compile Include="Utility\TextHelper.cs" />
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
Weben_CMSרÓôúÂëÉú³ÉÆ÷/Code/MainForm.Designer.cs
@@ -79,13 +79,14 @@
            this.tb_FilePath = new System.Windows.Forms.TextBox();
            this.btn_SelectFile = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.ck_IsDeletefile = new System.Windows.Forms.CheckBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // btnPath
            // 
            this.btnPath.Location = new System.Drawing.Point(453, 723);
            this.btnPath.Location = new System.Drawing.Point(425, 720);
            this.btnPath.Name = "btnPath";
            this.btnPath.Size = new System.Drawing.Size(97, 23);
            this.btnPath.TabIndex = 1;
@@ -564,11 +565,25 @@
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click_1);
            // 
            // ck_IsDeletefile
            //
            this.ck_IsDeletefile.AutoSize = true;
            this.ck_IsDeletefile.Checked = true;
            this.ck_IsDeletefile.CheckState = System.Windows.Forms.CheckState.Checked;
            this.ck_IsDeletefile.Location = new System.Drawing.Point(561, 724);
            this.ck_IsDeletefile.Name = "ck_IsDeletefile";
            this.ck_IsDeletefile.Size = new System.Drawing.Size(192, 16);
            this.ck_IsDeletefile.TabIndex = 50;
            this.ck_IsDeletefile.Text = "生成前是否先清理文件夹的文件";
            this.ck_IsDeletefile.UseVisualStyleBackColor = true;
            this.ck_IsDeletefile.CheckedChanged += new System.EventHandler(this.ck_IsDeletefile_CheckedChanged);
            //
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1402, 831);
            this.Controls.Add(this.ck_IsDeletefile);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.btn_SelectFile);
            this.Controls.Add(this.tb_FilePath);
@@ -645,6 +660,7 @@
        private System.Windows.Forms.Button btn_SelectFile;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.CheckBox ck_IsDeletefile;
    }
}
Weben_CMSרÓôúÂëÉú³ÉÆ÷/Code/MainForm.cs
@@ -283,6 +283,13 @@
                //CreateModelFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo);
                //CreateModelParamFile(columnList, tableName, filePrefixName, wcf_NameSpacePath, createPerson, chinaComment, entityName, modulelogo);
                genCodeRootPath = tbPath.Text + @"\" + tb_WCF_NameSpacePath.Text.Trim();
                //是否要事先清理文件夹
                if (this.ck_IsDeletefile.Checked)
                {
                    FileHelper.ClearFolder(genCodeRootPath); // é€’归删除
                }
                //var webFolerPath = (tb_WCF_NameSpacePath.Text.Trim() + "_Web").ToLower();
                var webFolerPath = _tb_VueRootFolerName;
                #region å®žä½“ç±»
@@ -825,5 +832,10 @@
        {
            this.tb_FilePath.Text = "";
        }
        private void ck_IsDeletefile_CheckedChanged(object sender, EventArgs e)
        {
        }
    }
}
Weben_CMSרÓôúÂëÉú³ÉÆ÷/Code/Utility/FileHelper.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,71 @@

using GenerateCode_GEBrilliantFactory;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GenerateCode_GEBrilliantFactory
{
    public class FileHelper
    {
        public static void DeleteAllContentsInFolder(string folderPath)
        {
            try
            {
                if (Directory.Exists(folderPath))
                {
                    // åˆ é™¤æ‰€æœ‰æ–‡ä»¶å’Œå­æ–‡ä»¶å¤¹ï¼ˆåŒ…括子文件夹中的文件)
                    foreach (string file in Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories))
                    {
                        File.Delete(file);
                        Console.WriteLine($"已删除文件: {file}");
                    }
                    // åˆ é™¤æ‰€æœ‰å­æ–‡ä»¶å¤¹ï¼ˆæ­¤æ—¶æ–‡ä»¶å¤¹å·²ç©ºï¼Œå¯ä»¥å®‰å…¨åˆ é™¤ï¼‰
                    foreach (string dir in Directory.GetDirectories(folderPath, "*", SearchOption.AllDirectories))
                    {
                        Directory.Delete(dir); // ä¸éœ€è¦é€’归,因为文件已被删除
                        Console.WriteLine($"已删除文件夹: {dir}");
                    }
                    Console.WriteLine($"成功清空文件夹 '{folderPath}' ä¸‹çš„æ‰€æœ‰å†…容。");
                }
                else
                {
                    Console.WriteLine($"文件夹不存在: {folderPath}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"删除文件/文件夹时出错: {ex.Message}");
            }
        }
        public static void ClearFolder(string folderPath)
        {
            try
            {
                if (Directory.Exists(folderPath))
                {
                    // åˆ é™¤æ‰€æœ‰æ–‡ä»¶å’Œå­æ–‡ä»¶å¤¹ï¼ˆåŒ…括子文件夹中的文件)
                    Directory.Delete(folderPath, true); // true è¡¨ç¤ºé€’归删除
                    Directory.CreateDirectory(folderPath); // é‡æ–°åˆ›å»ºç©ºæ–‡ä»¶å¤¹
                    Console.WriteLine($"已清空并重建文件夹 '{folderPath}'。");
                }
                else
                {
                    Console.WriteLine($"文件夹不存在: {folderPath}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"清空文件夹时出错: {ex.Message}");
            }
        }
    }
}