文件目录查看工具

简介: 实现代码: using System;using System.Collections.Generic;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace Windo

实现代码:

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

namespace WindowsFormsApp20140821
{
    public partial class FileSystem : Form
    {
        public FileSystem()
        {
            InitializeComponent();
            this.txtDirectoryInfo.Text = "F:\\";
        }

        private void BtnGet_Click(object sender, EventArgs e)
        {
            ClearAll();
            string folderName = this.txtDirectoryInfo.Text;
            this.txtCurrentDirectoryInfo.Text = folderName;
            try
            {
                DirectoryInfo folder = new DirectoryInfo(folderName);
                if(folder.Exists)
                {
                    GetDirectoryInfo(folderName);
                }

                FileInfo fileInfo = new FileInfo(folderName);
                if(fileInfo.Exists)
                {
                    GetFileInfo(folderName);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Message");
            }
        }

        private void GetFileInfo(string fileName)
        {
            FileInfo fileInfo = new FileInfo(fileName);
            if(fileInfo.Exists)
            {
                this.txtCreationTime.Text = fileInfo.CreationTime.ToLongDateString() + " "
                    + fileInfo.CreationTime.ToLongTimeString();
                this.txtFileSize.Text = fileInfo.Length.ToString() + " bytes";
                this.txtLastAccessTime.Text = fileInfo.LastAccessTime.ToLongDateString();
                this.txtLastWriteTime.Text = fileInfo.LastWriteTime.ToLongDateString();
            }
        }

        private void GetDirectoryInfo(string folderName)
        {
            DirectoryInfo folder = new DirectoryInfo(folderName);
            if(folder.Exists)
            {
                this.listBoxDirectoryInfos.Items.Clear();
                foreach (DirectoryInfo info in folder.GetDirectories())
                {
                    this.listBoxDirectoryInfos.Items.Add(info.Name);
                }
                this.listBoxFileInfos.Items.Clear();
                foreach(FileInfo info in folder.GetFiles())
                {
                    this.listBoxFileInfos.Items.Add(info.Name);
                }
            }      
        }
        private void ClearAll()
        {
            this.txtCreationTime.Text = "";
            this.txtFileSize.Text = "";
            this.txtLastAccessTime.Text = "";
            this.txtLastWriteTime.Text = "";
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            ClearAll();
            string currentFolderName = this.txtCurrentDirectoryInfo.Text;
            DirectoryInfo folder = new DirectoryInfo(currentFolderName);
            if (folder.Parent == null)
            {
                return;
            }
            currentFolderName = folder.Parent.FullName;
            this.txtCurrentDirectoryInfo.Text = currentFolderName;
            if (folder.Exists)
            {
                GetDirectoryInfo(currentFolderName);
            }
        }

        private void listBoxDirectoryInfos_MouseClick(object sender, MouseEventArgs e)
        {
            int index = listBoxDirectoryInfos.IndexFromPoint(e.X, e.Y);
            if (index != -1)
            {
                ClearAll();
                string fileName = this.listBoxDirectoryInfos.SelectedItem.ToString();
                string folderName = Path.Combine(this.txtCurrentDirectoryInfo.Text, fileName);
                this.txtCurrentDirectoryInfo.Text = folderName;
                DirectoryInfo info = new DirectoryInfo(folderName);
                if(info.Exists)
                {
                    GetDirectoryInfo(folderName);
                }
                FileInfo fileInfo = new FileInfo(folderName);
                if (fileInfo.Exists)
                {
                    GetFileInfo(folderName);
                }
            }
        }

        private void listBoxFileInfos_MouseClick(object sender, MouseEventArgs e)
        {
            int index = listBoxFileInfos.IndexFromPoint(e.X, e.Y);
            if (index != -1)
            {
                ClearAll();
                string fileName = this.listBoxFileInfos.SelectedItem.ToString();
                string folderName = Path.Combine(this.txtCurrentDirectoryInfo.Text, fileName);
                
                FileInfo fileInfo = new FileInfo(folderName);
                if (fileInfo.Exists)
                {
                    GetFileInfo(folderName);
                }
            }
        }

        private void txtDirectoryInfo_MouseClick(object sender, MouseEventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.ShowDialog();
            this.txtDirectoryInfo.Text = dialog.SelectedPath;
            BtnGet_Click(this, new EventArgs());
        }

        private void txtDirectoryInfo_TextChanged(object sender, EventArgs e)
        {
            this.txtCurrentDirectoryInfo.Text = this.txtDirectoryInfo.Text;
        }
    }
}

实现效果:


目录
相关文章
|
9天前
|
机器人 API 调度
基于 DMS Dify+Notebook+Airflow 实现 Agent 的一站式开发
本文提出“DMS Dify + Notebook + Airflow”三位一体架构,解决 Dify 在代码执行与定时调度上的局限。通过 Notebook 扩展 Python 环境,Airflow实现任务调度,构建可扩展、可运维的企业级智能 Agent 系统,提升大模型应用的工程化能力。
|
人工智能 前端开发 API
前端接入通义千问(Qwen)API:5 分钟实现你的 AI 问答助手
本文介绍如何在5分钟内通过前端接入通义千问(Qwen)API,快速打造一个AI问答助手。涵盖API配置、界面设计、流式响应、历史管理、错误重试等核心功能,并提供安全与性能优化建议,助你轻松集成智能对话能力到前端应用中。
715 154
|
15天前
|
人工智能 数据可视化 Java
Spring AI Alibaba、Dify、LangGraph 与 LangChain 综合对比分析报告
本报告对比Spring AI Alibaba、Dify、LangGraph与LangChain四大AI开发框架,涵盖架构、性能、生态及适用场景。数据截至2025年10月,基于公开资料分析,实际发展可能随技术演进调整。
963 152
|
负载均衡 Java 微服务
OpenFeign:让微服务调用像本地方法一样简单
OpenFeign是Spring Cloud中声明式微服务调用组件,通过接口注解简化远程调用,支持负载均衡、服务发现、熔断降级、自定义拦截器与编解码,提升微服务间通信开发效率与系统稳定性。
366 156
|
7天前
|
分布式计算 监控 API
DMS Airflow:企业级数据工作流编排平台的专业实践
DMS Airflow 是基于 Apache Airflow 构建的企业级数据工作流编排平台,通过深度集成阿里云 DMS(Data Management Service)系统的各项能力,为数据团队提供了强大的工作流调度、监控和管理能力。本文将从 Airflow 的高级编排能力、DMS 集成的特殊能力,以及 DMS Airflow 的使用示例三个方面,全面介绍 DMS Airflow 的技术架构与实践应用。
|
8天前
|
人工智能 自然语言处理 前端开发
Qoder全栈开发实战指南:开启AI驱动的下一代编程范式
Qoder是阿里巴巴于2025年发布的AI编程平台,首创“智能代理式编程”,支持自然语言驱动的全栈开发。通过仓库级理解、多智能体协同与云端沙箱执行,实现从需求到上线的端到端自动化,大幅提升研发效率,重塑程序员角色,引领AI原生开发新范式。
588 2