function : GetFiles
input 1 : 網站相對路徑
input 2 : 0 (int)
output : 2D Array
(0, n) : 檔案的 FullName (包含網站相對路徑)
(1, n) : 檔案的 Name
<%
dim TemporaryFiles()
function GetFiles(Path, FileCount)
set fs = Server.CreateObject("Scripting.FileSystemObject")
realfilepath = Server.Mappath(Path)
if fs.FolderExists(realfilepath) = true then
set folder = fs.GetFolder(realfilepath)
' 將目前資料夾下的檔案名稱放入陣列
for each f in folder.files
redim preserve TemporaryFiles(2, FileCount+1)
TemporaryFiles(0, FileCount) = Path & "/" & f.Name
TemporaryFiles(1, FileCount) = f.Name
FileCount = FileCount + 1
next
' 繼續找有沒有子資料夾, 有的話, 遞迴掃裡面的檔案和資料夾
for each subfolder in folder.SubFolders
call GetFiles(Path & "/" & subfolder.Name, FileCount)
next
set folder = nothing
else
redim TemporaryFiles(2, 1)
TemporaryFiles(0, 0) = ""
TemporaryFiles(1, 0) = "The path is not exist !"
end if
set fs = nothing
GetFiles = TemporaryFiles
end function
%>
<%
' 呼叫 function
FileArray = GetFiles("UserUpload", 0)
for i = 0 to ubound(FileArray,2)
response.write FileArray(0,i) & <br>
response.write FileArray(1,i) & <br>
next
%>
dim TemporaryFiles()
function GetFiles(Path, FileCount)
set fs = Server.CreateObject("Scripting.FileSystemObject")
realfilepath = Server.Mappath(Path)
if fs.FolderExists(realfilepath) = true then
set folder = fs.GetFolder(realfilepath)
' 將目前資料夾下的檔案名稱放入陣列
for each f in folder.files
redim preserve TemporaryFiles(2, FileCount+1)
TemporaryFiles(0, FileCount) = Path & "/" & f.Name
TemporaryFiles(1, FileCount) = f.Name
FileCount = FileCount + 1
next
' 繼續找有沒有子資料夾, 有的話, 遞迴掃裡面的檔案和資料夾
for each subfolder in folder.SubFolders
call GetFiles(Path & "/" & subfolder.Name, FileCount)
next
set folder = nothing
else
redim TemporaryFiles(2, 1)
TemporaryFiles(0, 0) = ""
TemporaryFiles(1, 0) = "The path is not exist !"
end if
set fs = nothing
GetFiles = TemporaryFiles
end function
%>
<%
' 呼叫 function
FileArray = GetFiles("UserUpload", 0)
for i = 0 to ubound(FileArray,2)
response.write FileArray(0,i) & <br>
response.write FileArray(1,i) & <br>
next
%>
沒有留言:
張貼留言