Folders and files Recursion复制一棵树

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UploadArchiveImage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            treeView1.AfterCheck += TreeView1_AfterCheck;
        }

        private void TreeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            this.treeView1.AfterCheck -= TreeView1_AfterCheck;
            checkNode(e.Node, e.Node.Checked);
            this.treeView1.AfterCheck += TreeView1_AfterCheck;
            this.treeView1.ResumeLayout();
        }

        private void checkNode(TreeNode node, bool ischecked)
        {
            node.Checked = ischecked;
            foreach (TreeNode c in node.Nodes)
            {
                checkNode(c, ischecked);
            }
        }

        private void btnLoadTree_Click(object sender, EventArgs e)
        {
            if (this.txtSourceFolder.Text.Length == 0)
            {
                MessageBox.Show("没有选择成果文件夹路径");
                return;
            }

            string path = this.txtSourceFolder.Text;
            var files = Directory.GetFiles(path);
            var folderInfo = new FolderInfo();
            folderInfo.Name = Path.GetFileName(path);
            foreach (string subFile in files)
            {
                folderInfo.Files.Add(Path.GetFileName(subFile));
            }
            string[] subDirs = Directory.GetDirectories(path);
            foreach (string subDir in subDirs)
            {
                folderInfo.Folders.Add(GetFilesRecursion1(subDir));
            }

            //加载到树
            this.treeView1.Nodes.Clear();
            var root = treeView1.Nodes.Add(folderInfo.Name);
            foreach (var f in folderInfo.Folders)
            {
                var c = root.Nodes.Add(f.Name + ((f.Folders.Count == 0) ? "(" + f.Files.Count.ToString() + ")" : ""));//加上文件个数的
                LoadFoldersToTree(c, f);
            }
        }

        private void LoadFoldersToTree(TreeNode node, FolderInfo fi)
        {
            foreach (var item in fi.Folders)
            {
                var child = node.Nodes.Add(item.Name + ((item.Folders.Count == 0)?"("+item.Files.Count.ToString()+")":""));
                LoadFoldersToTree(child, item);
            }
        }


        public FolderInfo GetFilesRecursion1(string pathname)
        {
            var fi = new FolderInfo();
            fi.Name = Path.GetFileName(pathname);
            string[] subFiles = Directory.GetFiles(pathname);
            foreach (string subFile in subFiles)
            {
                fi.Files.Add(subFile);
            }

            string[] subDirs = Directory.GetDirectories(pathname);
            foreach (string subDir in subDirs)
            {
                fi.Folders.Add(GetFilesRecursion1(subDir));
            }
            return fi;
        }

    }

    public class FolderInfo
    {
        public string Name { get; set; }
        private List<FolderInfo> _folders = new List<FolderInfo>();
        public List<FolderInfo> Folders { get { return this._folders; } set { this._folders = value; } }


        private List<string> _files = new List<string>();
        public List<string> Files { get { return this._files; } set { this._files = value; } }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Imagenet数据集是一个大规模的图像数据库,用于图像识别和分类任务。在训练和验证图像方面,Imagenet数据集是一个很好的选择。你提到的"imagenet-folder with train and val folders"可能是指Imagenet数据集预处理后的文件夹结构。 "imagenet-folder with train and val folders"是Imagenet数据集的典型文件夹结构,用于训练和验证图像模型。该结构通常包含两个主要文件夹:train(训练文件夹)和val(验证文件夹)。 在训练文件夹中,包含了大量用于训练图像模型的图像样本。这些图像样本通常根据类别进行文件夹组织,每个文件夹代表一个类别,包含该类别的训练样本。例如,文件夹"cat"中包含了不同品种的猫的图像。这种组织方式有助于模型学习每个类别的特征。 在验证文件夹中,包含了用于验证训练后模型性能的图像样本。这些图像样本也根据类别进行文件夹组织,但与训练文件夹不同的是,验证文件夹中的图像样本通常是模型在训练过程中未接触过的。通过验证文件夹中的图像样本,我们可以评估和测试模型对未知样本的泛化能力。 这种"imagenet-folder with train and val folders"的文件夹结构,可以帮助我们更好地组织和管理Imagenet数据集,方便训练和评估图像模型。同时,该结构也符合现有的机器学习框架和工具的要求,使得我们能够更轻松地处理和使用Imagenet数据集。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵之章

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值