文件遍历排序函数
有时需要遍历目录文件,但默认函数不支持指定排序的功能,现在我们引入一个sort-traverse目录方法,它默认按文件名的数量进行排序,本文是爱站技术频道为大家带来的文件遍历排序函数的介绍,希望能帮助到大家。
function bianli(path)
'initiate
path = server.mappath(path)
set fso=server.CreateObject("scripting.filesystemobject")
set objFolder=fso.GetFolder(path)
set objfiles = objfolder.files
'把文件名及文件路经存入theFiles数组
int slot = 0
Dim theFiles()
redim theFiles(50)
for each objFile in objFiles
filename = objFile.name
filePath = split(objFile.path,"docs\")
thepath1 = "./docs/"
thepath = thepath1 & filepath(1)
theFiles(slot) = filename&"**"&thepath
slot = slot + 1
if slot > UBound(theFiles) then
ReDim Preserve theFiles(Slot+20)
end if
next
ReDim Preserve theFiles(slot)
'冒泡排序
for i = 0 to UBound(theFiles)-2
for j = i+1 to UBound(theFiles)-1
if strComp(theFiles(i),theFiles(j)) = 1 then
tmp = theFiles(i)
theFiles(i) = theFiles(j)
theFiles(j) = tmp
end if
next
next
'输出
for i = 0 to UBound(theFiles)-1
para = theFiles(i)
filename = split(para,"**",-1,1)(0)
filepath = split(para,"**",-1,1)(1)
%>
next
end function
%>
上文就是爱站技术频道介绍的关于文件遍历排序函数,操作方法有很多,让我们慢慢学习,我们更应该掌握好这些一技之长,免得浪费了js.aizhan.com的大好资源。