显示多级目录和文件的源程序(转)



Directory List






Directory List



This script shows how to read a directory structure in ASP. The display belowshows the contents of a few directories located on this site, including anysubdirectories and their contents.


Each file is displayed as a link, so you can click on the file name to viewthat particular file.








How it Works


The script makes use of the FileScriptingObject which allows you to accessfiles and directories on the server. These objects contain properties thatdescribe the file or folder name, physical path, size, last modified date andother information.


Folder objects also contain collections of other FileScriptObjects for eachsubfolder and file in that directory.


The ListFolderContents subroutine does the work. It requires thephysical path to the folder, which can be found using the built-in
Server.MapPath() function. This function takes either a relative orabsolute URL and returns the physical path to that file. For example, the URL"/graphics/image.gif" might return a path of
"D:Inetpubwwwrootgraphicsimage.path". Either directories or files can beused.


Using Recursion


ListFolderContents first creates a Folder object using the given path.
It displays the folder name then loops through the SubFolders collection ofthat folder. For each subfolder it makes a recursive call to itself, passingthe subfolder path.


This causes it to walk down through the hierarchial directory structure anddisplay each subfolder and contents. The recursion stops down each branch whenit reaches a subfolder that has no subfolders of it's own.


Mapping a Physical Path to a URL


After listing all subfolders, ListFolderContents then loops through theFiles collection, displaying each file name to complete the contents displayfor the given folder.


Each file is displayed as a standard HTML link. Unfortunately the
Server.MapPath() function has no compliment to convert a physical pathback to a URL. But this is not difficult to do and the script includes afunction called MapURL that takes the file path and returns a valid URLthat can be used to link to it.


Notes on the Example


To list the entire site structure you could simply call
ListFolderContents once with path to the web site root at the argument.


 





For the example on this page however, only a few subdirectories are used.
Otherwise the display would be several pages long. So separate calls are madefor each subdirectory to be shown.


 







Source








Home



  dim fs, folder, file, item, url

  set fs = CreateObject("Scripting.FileSystemObject")
  set folder = fs.GetFolder(path)

  Response.Write("

" & folder.Name & "" & vbCrLf)
  Response.Write("
  • " & vbCrLf)

  'Display sub folders.

  for each item in folder.SubFolders
   ListFolderContents(item.Path)
  next

  'Display files.

  for each item in folder.Files
   url = MapURL(item.path)
   Response.Write("

" & item.name & "
" & vbCrLf)
  next

  Response.Write("

" & vbCrLf)

 end sub

 function MapURL(path)

  dim rootPath, url

  'Convert a physical file path to a URL.

  rootPath = Server.MapPath("/")
  url = Right(path, Len(path) - Len(rootPath))
  MapURL = Replace(url, "", "/")

 end function %>


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124709/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124709/

1 概述 文件系统是操作系统用于明确存储设备(常见的是磁盘,也有基于NAND Flash的固态硬盘)或分区上的文件的方法数据结构;即在存储设备上组织文件的方法。操作系统中负责管理存储文件信息的软件机构称为文件管理系统,简称文件系统。文件系统由三部分组成:文件系统的接口,对对象操纵管理的软件集合,对象及属性。从系统角度来看,文件系统是对文件存储设备的空间进行组织分配,负责文件存储并对存入的文件进行保护检索的系统。具体地说,它负责为用户建立文件,存入、读出、修改、文件,控制文件的存取,当用户不再使用时撤销文件等。 本次实验我们实现了多级目录下的文件管理系统,具备文件系统的文件创建、删除、读写以及目录的创建、删除等操作,并在内存中开辟一块空间,模拟虚拟磁盘,成功地展示出文件系统的功能属性。 2 课程设计的任务要求 2.1 设计任务 在下列内容中任选其一: 1、多用户、多级目录结构文件系统的设计与实现; 2、WDM驱动程序开发; 3、存储管理系统的实现,主要包括虚拟存储管理调页、缺页统计等; 4、进程管理系统的实现,包括进程的创建、调度、通信、撤消等功能; 5、自选一个感兴趣的与操作系统有关的问题加以实现,要求难度相当。 2.2 设计要求 1、在深入理解操作系统基本原理的基础上,对于选定的题目,以小组为单位,先确定设计方案; 2、设计系统的数据结构程序结构,设计每个模块的处理流程。要求设计合理; 3、编程序实现系统,要求实现可视化的运行界面,界面应清楚地反映出系统的运行结果; 4、确定测试方案,选择测试用例,对系统进行测试; 5、运行系统并要通过验收,讲解运行结果,说明系统的特色创新之处,并回答指导教师的提问; 6、提交课程设计报告。 集体要求: 1.在内存中开辟一个虚拟磁盘空间作为文件存储器,在其上实现一个多用户多目录文件系统。 2.文件物理结构可采用显式链接或其他方法。 3.磁盘空闲空间的管理可选择位示图或其他方法。如果采用位示图来管理文件存储空间,并采用显式链接分配方式,则可以将位示图合并到FAT中。 4.文件目录结构采用多用户多级目录结构,每个目录项包含文件名、物理地址、长度等信息,还可以通过目录项实现对文件的读写的保护。目录组织方式可以不使用索引结点的方式,但使用索引结点,则难度系数为1.2。 5.设计一个较实用的用户界面,方便用户使用。要求提供以下相关文件操作: (1)具有login (用户登录) (2)系统初始化(建文件卷、提供登录模块) (3)文件的创建: create (4)文件的打开:open (5)文件的读:read (6)文件的写:write (7)文件关闭:close (8)删除文件:delete (9)创建目录(建立子目录):mkdir (10)改变当前目录:cd (11)列出文件目录:dir (12)退出:logout ................................................
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值