欢迎光临
我们一直在努力

ASP编程入门进阶(十八):FSO组件之文件操作(下)-ASP教程,ASP应用

建站超值云服务器,限时71元/月

一,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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP编程入门进阶(十八):FSO组件之文件操作(下)-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章