程序员的出路

alex.w的Blog

导航

ASP FSO详解-对普通文件的操作

Posted on 2008-10-15 15:13  alex.w  阅读(312)  评论(0)    收藏  举报

PART FOUR  FSO对文件的操作
FSO针对文件夹的方法有5种
1. CopyFile source,destination,[true];
  
复制文件,可通过通配符复制多个文件,可覆盖已有文件
    eg: FSO.CopyFile "d:\ test6.txt","d:\ctest1.txt"
2. MoveFile source,destination:
    移动文件,可通过通配符移动多个文件,如目的文件已存在则报错 
    eg: FSO.MoveFile "d:\ test6.txt","d:\ ctest2.txt"
3. DeleteFile FileSpecifier:
 
 删除文件,可通过通配符删除多个文件,如无目的文件则报错
   eg: FSO.DeleteFile("d:\ test3.txt")
4. FileExists(file) 
   检测文件是否存在,返回True或False 
   eg:fso.fileExists(“c:/www.txt”)
5. getFile(file) 为制定文件一个File对象

 

fso.getFile方法获取一个File对象,并可进行如下操作:

  1. name: 文件名称
  2. path: 文件物理路径
  3. shortPath: 文件短路径名
  4. Attributes: 文件属性 返回值:0 1 2 4 16 32 129
                 Normal 0 普通文件。 没有设置任何属性。
                 ReadOnly 1 只读文件。 可读写。
                 Hidden 2 隐藏文件。 可读写。
                 System 4 系统文件。 可读写。
                 Directory 16 文件夹或目录。 只读。
                 Archive 32 上次备份后已更改的文件。 可读写。
                 Alias 64 链接或快捷方式。 只读。
                 Compressed 129 压缩文件。 只读。 
  5. size: 文件大小
  6. type: 文件类型
  7. drive: 文件所在盘符
  8. DateCreated: 文件创建时间
  9. DateLastAccessed: 文件最近访问时间
  10. DateLastModified: 文件最后修改时间
  11. Copy “dir”[,true]: 将当前文件创建一个拷贝
  12. Move “dir”: 移动当前文件
  13. Delete: 删除当前文件

 

FSO.getFile的方法:
<%
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)
f2.copy “d:/”
response.write “<a href=’D:\’>查看下有没有</a>”
f2.move “c:/”
response.write “<a href=’C:\’>查看下有没有</a>”
f2.close
set f2=fso.getFile(“c:/cnbruce.txt”)
f2.delete
response.write “<a href=’C:\’>查看下有没有</a>”