FSO遍历文件夹中的文件并按创建时间排序
|
Ccoffee
2010年7月16日 15:49
本文热度 4462
|
[code]
[p]
[br] [br] 文件 | [br] 创建日期 | [br]
[br]<%[br]foldpath=server.mappath([color=#ff33ff]"../images/uploadfiles"[/color])[br][color=#0000ff]set[/color] fso = server.[color=#ff0000]createobject[/color]([color=#ff33ff]"scripting.filesystemobject"[/color])[br][color=#0000ff]set[/color] fsofolder=fso.getfolder(foldpath)[br][color=#0000ff]set[/color] getfiles =fsofolder.files[br]'定义数组[br][color=#0000ff]dim[/color] filearr(),i[br]i=0[br][color=#0000ff]for[/color] [color=#0000ff]each[/color] f [color=#0000ff]in[/color] getfiles[br][color=#0000ff]redim[/color] preserve filearr(i)[br] temp=f.datecreated'取出文件建立时间[br] filearr(i)=temp[br]i=i+1[br][color=#0000ff]next[/color][br]'对文件建立时间排序[br][color=#0000ff]for[/color] m=0 [color=#0000ff]to[/color] i-1[br] [color=#0000ff]for[/color] n=m [color=#0000ff]to[/color] i-1[br] [color=#0000ff]if[/color]([color=#ff0000]cdate[/color](filearr(m))<[color=#ff0000]cdate[/color](filearr(n)))[color=#0000ff]then[/color][br] ordertemp=filearr(m)[br] filearr(m)=filearr(n)[br] filearr(n)=ordertemp[br] [color=#0000ff]end[/color] [color=#0000ff]if[/color][br] [color=#0000ff]next[/color][br][color=#0000ff]next[/color][/p]
[p][color=#0000ff]for[/color] m=0 [color=#0000ff]to[/color] i-1[br] [color=#0000ff]for[/color] [color=#0000ff]each[/color] f [color=#0000ff]in[/color] getfiles[br] temp=f.datecreated[br] [color=#0000ff]if[/color]([color=#ff0000]cdate[/color](temp)=[color=#ff0000]cdate[/color](filearr(m)))[color=#0000ff]then[/color][br]%>[br] [br] [br]<%[br] file_name=f.name[br] [color=#ff0000]response[/color].write file_name[br]%>[br] | [br] <%=f.datecreated%> | [br]
[br]<%[br] [color=#0000ff]end[/color] [color=#0000ff]if[/color][br] [color=#0000ff]next[/color][br][color=#0000ff]next[/color][br]%>[br]
[/p][/code]
该文章在 2010/7/16 15:49:51 编辑过