本文的示例是在asp中遍歷某路徑下文件夾,并把所有MP3數(shù)據(jù)讀到數(shù)據(jù)庫中,具體實現(xiàn)如下:
<!–#include file=”Sql_Conn.asp”–><!–#include file=”Inc/Inc.asp”–><!–#include file=”Inc/Config.asp”–>
<%
function GetExtendName(FileName)
dim ExtName
ExtName = LCase(FileName)
ExtName = right(ExtName,3)
ExtName = right(ExtName,3-Instr(ExtName,”.”))
GetExtendName = ExtName
end function
‘便歷某路徑下文件夾,把所有MP3數(shù)據(jù)讀到數(shù)據(jù)庫
function bianli(path)
dim fso ‘fso對象
dim objFolder ‘文件夾對象
dim objSubFolders ‘子文件夾集合
dim objSubFolder ‘子文件夾對象
dim objFiles ‘文件集合
dim objFile ‘文件對象
set fso=server.CreateObject(“scripting.filesystemobject”)
on error resume next
set objFolder=fso.GetFolder(path)’創(chuàng)建文件夾對象
set objSubFolders=objFolder.Subfolders’創(chuàng)建的子文件夾對象
for each objSubFolder in objSubFolders
‘nowpath=path + “\” + objSubFolder.name
nowpath=path + objSubFolder.name
‘ Response.Write nowpath
set objFiles=objSubFolder.Files
for each objFile in objFiles
if GetExtendName(objFile.name) = “mp3” then
Response.Write “<br>”
‘Response.Write objFile.name
dim lc_lj
lc_lj = nowpath + “/” +objFile.name
lc_lj=Mid(lc_lj,4) ‘ 由lc_lj的第4個字符讀起,讀取后面的所有字符。
lc_lj=Replace(lc_lj,””,”/”)
‘response.Write(lc_lj)
dim lc_now
lc_now = now()
response.write lc_now
dim sql_in
‘sql_in = “insert into ylmv_dj(djCat_Id,specialid,Dj_name,Hits,dj_url,path,dj_pic,dj_user,tjuser,dj_word,dj_desc,IsBest,istop,grade,DownHits,BoxHits,uHits,dHits,DayHits,WeekHits,MonthHits,error,passed,points,music,dj_date,lasthittime) values(11,0,'”+ objFile.name +”‘,0,'”+ lc_lj +”‘,5,’rm’,’紫龍舞曲管理’,’admin’,'”+ objFile.name +”‘,’☆☆★★★’,1,1,1,0,0,0,0,0,0,0,0,0,0,0,'”+lc_now +”‘,'”+lc_now+”‘)”
sql_in1 = “insert into ylmv_dj(djCat_Id,specialid,Dj_name,Hits,dj_url,path,dj_pic,dj_user,tjuser,dj_word,dj_desc,IsBest,istop,grade,DownHits,BoxHits,uHits,dHits,DayHits,WeekHits,MonthHits,error,passed,points,music,deleted) values(11,0,'”+ objFile.name +”‘,0,'”+ lc_lj +”‘,5,’rm’,’紫龍舞曲管理’,’admin’,'”+ objFile.name +”‘,’☆☆★★★’,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0)”
‘Response.Write objFile.name
‘response.Write sql_in1
conn.execute(sql_in1)
Response.Write “<br>”
response.Write(“添加”+objFile.name+”!!!!!!”)
end if
next
Response.Write “<p>”
bianli(nowpath) ‘調(diào)用遞歸
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli(“F:Music”) ‘調(diào)用bianli()函數(shù),這里是遍歷F:盤
%>