惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
量子位
A
About on SuperTechFans
G
Google Developers Blog
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 迷梦江南

DB2问题记录本 AS3无缝循环播放FLV flex开发零碎笔记,随时补充 AS3淡入淡出类 JQuey练习一 转“大型网站架构演变和知识体系” 转“大型高并发高负载网站的系统架构 ” 转“经验分享:大型高并发高负载网站的系统架构 ” 转“关于平台研发的一些想法” 转“国内图片网站Yupoo的架构” mootools 1-4 ajax C#测试代码段运行速度 - 迷梦江南 - 博客园 javascript放大图片 - 迷梦江南 - 博客园 javascript网站导航栏 - 迷梦江南 - 博客园 QQ在线状态接口 - 迷梦江南 - 博客园 (转)Javascript在IE与Firefox下的差异 WebApplication与Profile购物车 网站发布后出现的两个问题 mootools实现搜索提示文本框修正版
ASP.NET查看本地磁盘下的子目录和文件信息
迷梦江南 · 2007-11-30 · via 博客园 - 迷梦江南

今天做了个小示例,用编程的方式查看本地磁盘下的子目录和文件信息。不足的地方还望提醒,代码如下:

<%@ Page Language="C#" %>

<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%

    string[] directory = Directory.GetLogicalDrives();//获取电脑上所有格式为“<驱动器号>:"”的驱动器(如:C:",D:",E:",...)

    for (int k = 0; k < directory.Length; k++)

    {

        Response.Write("驱动器" + directory[k]);

        string strDir2List = directory[k].ToString();

        DirectoryInfo thisOne = null;

        try

        {

            thisOne = new DirectoryInfo(strDir2List);//在指定的驱动器路径中创建驱动器信息实例

            Response.Write("<tablewidth:100%;"" border=""1"">");

            Response.Write("<tr>");

            Response.Write("<tdwidth:20%;"" >");

            Response.Write("名称");

            Response.Write("</td>");

            Response.Write("<tdwidth:20%;"" >");

            Response.Write("路径");

            Response.Write("</td>");

            Response.Write("<td>");

            Response.Write("完整路径");

            Response.Write("</td>");

            Response.Write("<tdwidth:12%;"" >");

            Response.Write("创建时间");

            Response.Write("</td>");

            Response.Write("<td>");

            Response.Write("大小");

            Response.Write("</td>");

            Response.Write("<tdwidth:12%;"">");

            Response.Write("上次访问时间");

            Response.Write("</td>");

            Response.Write("<tdwidth:12%;"">");

            Response.Write("上次修改时间");

            Response.Write("</td>");

            DirectoryInfo[] subDirectories = thisOne.GetDirectories();//获取当前目录下所有的子目录

            for (int i = 0; i < subDirectories.Length; i++)

            {

                Response.Write("<tr>");

                Response.Write("<td>");

                Response.Write(subDirectories[i].Name);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(subDirectories[i].FullName);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(" ");

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(subDirectories[i].CreationTime);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(" ");

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(subDirectories[i].LastAccessTime);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(subDirectories[i].LastWriteTime);

                Response.Write("</td>");

                Response.Write("</tr>");

            }

            FileInfo[] fInfo = thisOne.GetFiles();//获取当前目录下所有的文件

            for (int i = 0; i < fInfo.Length; i++)

            {

                Response.Write("<tr>");

                Response.Write("<td>");

                Response.Write(fInfo[i].Name);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].FullName);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].DirectoryName);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].CreationTime);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].Length + " B");

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].LastAccessTime);

                Response.Write("</td>");

                Response.Write("<td>");

                Response.Write(fInfo[i].LastWriteTime);

                Response.Write("</td>");

                Response.Write("</tr>");

            }

            Response.Write("</tr>");

            Response.Write("</table>");

        }

        catch (Exception ex)

        {

            Response.Write(ex.ToString());

            Response.End();

        }

    }

    %>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>无标题页</title>

</head>

<body>

</body>

</html>