[求助]asp FSO操作,取出文件夹下的最新的文件

lonz 2004-11-24 09:01:13
要实现的功能是:
取出一个文件夹下 最新的 那个文件的文件名!

谢谢
...全文
120 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xczhouyang 2004-11-24
  • 打赏
  • 举报
回复
888228(同志,请记得结贴!)
我觉得你的方法可能会比 lonz() 的速度更慢慢,比较了一下我觉得lonz() 好
lonz 2004-11-24
  • 打赏
  • 举报
回复
明白了。谢谢大家!
888228 2004-11-24
  • 打赏
  • 举报
回复
直接读取应该是不行的.我查了很多相关资料的.都是先弄成数组.然后再排序.毕竟不象数据库,可以Order by..


如果是要读取最新的1个文件.用以下代码吧~~



dim folderPath
folderPath = Server.MapPath("images/") '修改成你要的路径,对这个路径下的文件按日期排列
dim fso,f
set fso=server.CreateObject("Scripting.filesystemobject")
set fld=fso.Getfolder(folderPath)

for each f in fld.files
dd=f.DateLastModified
dd1=year(dd)&"-"&right("0"&month(dd),2)&"-"&right("0"&day(dd),2)&" "
str=str&dd1&f.name&"|"
'response.write f.DateLastModified&f.name &"<br/>"
i=i+1
next

tmp=split(str,"|")
for j=0 to ubound(tmp)
str1=""
for i=0 to ubound(tmp)
if i=ubound(tmp) then exit for
if tmp(i)<=tmp(i+1) then
tt=tmp(i)
tmp(i)=tmp(i+1)
tmp(i+1)=tt
end if
str1=str1&tmp(i)&"|"
next
next

tmp1=split(str1,"|")

response.write num1&". "&tmp1(0)&"<br/>"
xczhouyang 2004-11-24
  • 打赏
  • 举报
回复
lonz() 你办法算是好的了,除非能够读取时直接排序,但好象没有直接排序的
sfply 2004-11-24
  • 打赏
  • 举报
回复
我也在想这个问题,如何使用WINDOWS的排序方式让目录按要求排序
lonz 2004-11-24
  • 打赏
  • 举报
回复
能不能读取的时候就直接排序。取第一个就可以了??


下面是我自己写的一段。不过感觉速度有点慢!!
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("E:\jpg")
'列出文件
Set fc = f.Files
dim LastestFileName
dim LastFileDate

LastFileDate="2000-11-12 20:12:04"
For Each f1 in fc
if (Cstr(f1.datelastmodified) > LastFileDate) then
LastFileDate=f1.datelastmodified
LastestFileName=f1.name
end if

Next
set fso=nothing
888228 2004-11-24
  • 打赏
  • 举报
回复
上面是对整个目录的文件进行读取,按照时间排列.

你如果只要最新的那个的话,就改成循环一次就行了.
888228 2004-11-24
  • 打赏
  • 举报
回复
<%
dim folderPath
folderPath = Server.MapPath("images/") '修改成你要的路径,对这个路径下的文件按日期排列
dim fso,f
set fso=server.CreateObject("Scripting.filesystemobject")
set fld=fso.Getfolder(folderPath)
for each f in fld.files
dd=f.DateLastModified
dd1=year(dd)&"-"&right("0"&month(dd),2)&"-"&right("0"&day(dd),2)&" "
str=str&dd1&f.name&"|"
'response.write f.DateLastModified&f.name &"<br/>"
next
tmp=split(str,"|")
for j=0 to ubound(tmp)
str1=""
for i=0 to ubound(tmp)
if i=ubound(tmp) then exit for
if tmp(i)<=tmp(i+1) then
tt=tmp(i)
tmp(i)=tmp(i+1)
tmp(i+1)=tt
end if
str1=str1&tmp(i)&"|"
next
next
tmp1=split(str1,"|")
for k= 0 to ubound(tmp1)-1
num1=num1+1
response.write num1&". "&tmp1(k)&"<br/>"
next%>
TSD 2004-11-24
  • 打赏
  • 举报
回复
看看这个,然后将文件时间作个对比就行了
http://community.csdn.net/Expert/TopicView.asp?id=3568110

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧