用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 程序开发教程 > ASP教程 > ASP实例教程 > 文章正文
ASP编程入门进阶(十八):FSO组件之文件操作(下)
iTbulo.COM 2005-7-6 ASP()

  一,fso.GetFile
  提取文件相应的 File 对象

  1,getfile.asp


<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)

s = "文件名称:" & f2.name & "<br>"
s = s & "文件短路径名:" & f2.shortPath & "<br>"
s = s & "文件物理地址:" & f2.Path & "<br>"
s = s & "文件属性:" & f2.Attributes & "<br>"
s = s & "文件大小: " & f2.size & "<br>"
s = s & "文件类型: " & f2.type & "<br>"
s = s & "文件创建时间: " & f2.DateCreated & "<br>"
s = s & "最近访问时间: " & f2.DateLastAccessed & "<br>"
s = s & "最近修改时间: " & f2.DateLastModified
response.write(s)
%>

  其效果正如右键某文件,看到的具体属性信息。
  其中Attributes返回的数值“32”表示:(Archive)上次备份后已更改的文件。可读写。

  其它值附录如下:

 
Normal 0 普通文件。 没有设置任何属性。
ReadOnly 1 只读文件。 可读写。
Hidden 2 隐藏文件。 可读写。
System 4 系统文件。 可读写。
Directory 16 文件夹或目录。 只读。
Archive 32 上次备份后已更改的文件。 可读写。
Alias 1024 链接或快捷方式。 只读。
Compressed 2048 压缩文件。 只读。

  二,file.move
  作用将指定的文件或文件夹从某位置移动到另一位置。其实该方法仍然属于fso.GetFile后的一个应用。

  2,movefile.asp


<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.Move "C:\"
%>
<a href="C:\">查看下有没有</a>


  简单的剪切粘贴的功能实现。

  三,File.Copy
  同样属于fso.GetFile后的一个应用。就只是单纯地拷贝文件到某位置。

  3,copyfile.asp


<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.Copy "D:\"
%>
<a href="D:\">查看下有没有</a>

  和本ASP页面同在目录下的cnbruce.txt文件依然存在。

  四,file.Delete
  很显然,就是直接删除文件了。

  4,delfile.asp


<%
whichfile=Server.MapPath("cnbruce.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(whichfile,true)
f1.Write ("This is a test.My Name is cnbruce.")
f1.Close
Set f2 = fso.GetFile(whichfile)
f2.move "d:\"
Set f3 = fso.GetFile("d:\cnbruce.txt")
f3.delete
%>
<a href="d:\">查看下是没有该文件的</a>

  当然FSO还没有结束,比如上传文件,ASP转HTML等都需要用到FSO。更精彩的依然是在后面。

 

文章搜索
相关资讯
相关文章 相关下载
ASP编程入门进阶(二十二):ADO组件之分页程序
ASP编程入门进阶(二十一):ADO组件之插入数据记录
ASP编程入门进阶(二十):ADO组件之显示数据记录
ASP编程入门进阶(十九):ASP技巧累加(2)
ASP编程入门进阶(十八):FSO组件之文件操作(中)
焦点信息