asp fso讀取資料夾,如何按照時間排序

2021-06-08 00:10:14 字數 3471 閱讀 7537

讀取乙個資料夾或子資料夾內的所有檔案範例

<%

dim objfso,objfolder,objfile,ff '宣告 objfso 變數存放物件例項

set objfso = server.createobject("scripting.filesystemobject")

if objfso.folderexists(ff) then

response.write "資料夾 "&ff&" 裡所有的檔案:

" set objfolder = objfso.getfolder(ff)

for each objfile in objfolder.files

response.write objfile.name & "

" next

else

response.write "資料夾"&ff&"不存在,無法讀取相關資訊!"

end if

set objfolder = nothing

set objfso = nothing '釋放 filesystemobject 物件例項記憶體空間

%>

但是怎麼排序呢??

private type typfliedate

name as string

createddate as date

accesseddate as date

modifieddate as date

end type

private myfiles() as typfliedate '包含檔案的陣列

private sub command1_click()

dim n as integer

n = getfolderfiles("d:\", 1)

end sub

private function getfolderfiles(path as string, orderby as integer) as integer

'path 資料夾路徑

'orderby 排序依據 1:按建立時間 2:按訪問時間 3:按修改時間 4:按名稱

'返回資料夾中檔案的個數

'如果要計算子資料夾可以通過 fldr.subfolders 訪問,方法類似

dim tmpfile as typfliedate

dim n as integer, i as integer, j as integer

dim fso as new filesystemobject

dim fldr as folder

dim fls as files

dim fl as file

'讀去檔案

set fso = createobject("scripting.filesystemobject")

set fldr = fso.getfolder(path)

set fls = fldr.files

n = fls.count

if n > 0 then

redim myfiles(n - 1)

i = 0

for each fl in fls

myfiles(i).name = fl.name

myfiles(i).accesseddate = fl.datelastaccessed

myfiles(i).createddate = fl.datecreated

myfiles(i).modifieddate = fl.datelastmodified

i = i + 1

next

'排序 --- 公升序

for i = 0 to n - 1

for j = i + 1 to n - 1

select case orderby

case 1 '建立時間

if myfiles(i).createddate > myfiles(j).createddate then

tmpfile = myfiles(i)

myfiles(i) = myfiles(j)

myfiles(j) = tmpfile

' tmpfile.name = myfiles(i).name

' tmpfile.accesseddate = myfiles(i).accesseddate

' tmpfile.createddate = myfiles(i).createddate

' tmpfile.modifieddate = myfiles(i).modifieddate

' ' myfiles(i).accesseddate = myfiles(j).accesseddate

' myfiles(i).createddate = myfiles(j).createddate

' myfiles(i).modifieddate = myfiles(j).modifieddate

' myfiles(i).name = myfiles(j).name

' ' myfiles(j).accesseddate = tmpfile.accesseddate

' myfiles(j).createddate = tmpfile.createddate

' myfiles(j).modifieddate = tmpfile.modifieddate

' myfiles(j).name = tmpfile.name

end if

case 2 '訪問時間

if myfiles(i).accesseddate > myfiles(j).accesseddate then

tmpfile = myfiles(i)

myfiles(i) = myfiles(j)

myfiles(j) = tmpfile

end if

case 3 '修改時間

if myfiles(i).modifieddate > myfiles(j).modifieddate then

tmpfile = myfiles(i)

myfiles(i) = myfiles(j)

myfiles(j) = tmpfile

end if

case 4 '名稱

if ucase(myfiles(i).name) > ucase(myfiles(j).name) then

tmpfile = myfiles(i)

myfiles(i) = myfiles(j)

myfiles(j) = tmpfile

end if

end select

next j

next i

end if

getfolderfiles = n

end function

php讀取資料夾內檔案及資料夾

php讀取資料夾內檔案及資料夾 引數 資料夾路徑 dir,格式要求 資料夾名稱後必須有 返回值 含有檔名稱和路徑的一維陣列 function read dir else 進行路徑拼接 allfile array merge file arr,dir arr 拼合陣列 return allfile f...

Python按照指定順序讀取資料夾中的檔案

1.首先不得不說的是python中的os.listdir 方法。os.listdir 方法用於返回指定的資料夾包含的檔案或資料夾的名字的列表。但是,os.listdir 返回的檔名不一定是順序的,這就要求我們對返回的檔名列表進行排序 假設我們有乙個這樣的資料夾 我們利用os.listdir 方法寫出...

php讀取資料夾許可權

說明 摘錄自 user manager for pureftpd 的許可權顯示函式 整理 功能 讀取資料夾許可權 function displayfilepermissions mode else if mode 0x2000 else if mode 0x4000 else if mode 0x6...