2023-10-11 分類: 網(wǎng)站建設(shè)
'建立文件存儲對象函數(shù)
Function createStreamFile(Byval stream,Byval fileDir)
dim errid,errdes
fileDir=replace(fileDir, "\", "/")
call createfolder(fileDir,"filedir")
on error resume next
With objStream
.Type =1
.Mode=3
.Open
.write stream
.SaveToFile server.mappath(fileDir),2
.close
End With
if Err Then error.clear:createStreamFile=false else createStreamFile=true
End Function
'建立文件目錄函數(shù)
Function createFolder(Byval dir,Byval dirType)
dim subPathArray,lenSubPathArray, pathDeep, i
on error resume next
dir=replace(dir, "\", "/")
dir=replace(server.mappath(dir), server.mappath("/"), "")
subPathArray=split(dir, "\")
pathDeep=pathDeep&server.mappath("/")
select case dirType
case "filedir"
lenSubPathArray=ubound(subPathArray) - 1
case "folderdir"
lenSubPathArray=ubound(subPathArray)
end select
for i=1 to lenSubPathArray
pathDeep=pathDeep&"\"&subPathArray(i)
if not objFso.FolderExists(pathDeep) then objFso.CreateFolder pathDeep
next
if Err Then createFolder=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_createFolder,errid,errdes else createFolder=true
End Function
'檢查文件是否存在函數(shù)
Function isExistFile(Byval fileDir)
on error resume next
If (objFso.FileExists(server.MapPath(fileDir))) Then isExistFile=True Else isExistFile=False
if err then err.clear:isExistFile=False
End Function
'檢查文件目錄是否存在函數(shù)
Function isExistFolder(Byval folderDir)
on error resume next
If objFso.FolderExists(server.MapPath(folderDir)) Then isExistFolder=True Else isExistFolder=False
if err then err.clear:isExistFolder=False
End Function
'刪除文件目錄函數(shù)
Function delFolder(Byval folderDir)
on error resume next
If isExistFolder(folderDir)=True Then
objFso.DeleteFolder(server.mappath(folderDir))
if Err Then delFolder=false : errid=err.number : errdes=err.description:Err.Clear : echoErr err_delFolder,errid,errdes else delFolder=true
else
delFolder=false : die(err_notExistFolder)
end if
End Function
'刪除文件函數(shù)
Function delFile(Byval fileDir)
on error resume next
If isExistFile(fileDir)=True Then objFso.DeleteFile(server.mappath(fileDir))
if Err Then delFile=false : errid=err.number : errdes=err.description:Err.Clear : echoErr err_delFile,errid,errdes else delFile=true
End Function
'檢查文件是否存在函數(shù)
Function initializeAllObjects()
dim errid,errdes
on error resume next
if not isobject(objFso) then set objFso=server.createobject(FSO_OBJ_NAME)
If Err Then errid=err.number:errdes=err.description:Err.Clear:echoErr err_fsoobj,errid,errdes
if not isobject(objStream) then Set objStream=Server.CreateObject(STREAM_OBJ_NAME)
If Err Then errid=err.number:errdes=err.description:Err.Clear:echoErr err_stmobj,errid,errdes
End Function
'檢查文件操作組件函數(shù)
Function terminateAllObjects()
on error resume next
if conn.isConnect then conn.close
if isobject(conn) then : set conn=nothing
if isobject(objFso) then set objFso=nothing
if isobject(objStream) then set objStream=nothing
if isobject(cacheObj) then set cacheObj=nothing
if isobject(mainClassObj) then set mainClassObj=nothing
if isObject(gXmlHttpObj) then SET gXmlHttpObj=Nothing
End Function
'移動文件目錄函數(shù)
Function moveFolder(oldFolder,newFolder)
dim voldFolder,vnewFolder
voldFolder=oldFolder
vnewFolder=newFolder
on error resume next
if voldFolder <> vnewFolder then
voldFolder=server.mappath(oldFolder)
vnewFolder=server.mappath(newFolder)
if not objFso.FolderExists(vnewFolder) then createFolder newFolder,"folderdir"
if objFso.FolderExists(voldFolder) then objFso.CopyFolder voldFolder,vnewFolder : objFso.DeleteFolder(voldFolder)
if Err Then moveFolder=false : errid=err.number : errdes=err.description:Err.Clear : echoErr err_moveFolder,errid,errdes else moveFolder=true
end if
End Function
'移動文件函數(shù)
Function moveFile(ByVal src,ByVal target,Byval operType)
dim srcPath,targetPath
srcPath=Server.MapPath(src)
targetPath=Server.MapPath(target)
if isExistFile(src) then
objFso.Copyfile srcPath,targetPath
if operType="del" then delFile src
moveFile=true
else
moveFile=false
end if
End Function
'取得文件夾列表函數(shù)
Function getFolderList(Byval cDir)
dim filePath,objFolder,objSubFolder,objSubFolders,i
i=0
redim folderList(0)
filePath=server.mapPath(cDir)
set objFolder=objFso.GetFolder(filePath)
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders
ReDim Preserve folderList(i)
With objSubFolder
folderList(i)=.name&",文件夾,"&.size/1000&"KB,"&.DateLastModified&","&cDir&"/"&.name
End With
i=i + 1
next
set objFolder=nothing
set objSubFolders=nothing
getFolderList=folderList
End Function
'取得文件列表函數(shù)
Function getFileList(Byval cDir)
dim filePath,objFolder,objFile,objFiles,i
i=0
redim fileList(0)
filePath=server.mapPath(cDir)
set objFolder=objFso.GetFolder(filePath)
set objFiles=objFolder.Files
for each objFile in objFiles
ReDim Preserve fileList(i)
With objFile
fileList(i)=.name&","&Mid(.name, InStrRev(.name, ".") + 1)&","&.size/1000&"KB,"&.DateLastModified&","&cDir&"/"&.name
End With
i=i + 1
next
set objFiles=nothing
set objFolder=nothing
getFileList=fileList
End Function
'讀取文件內(nèi)容函數(shù)
Function loadFile(ByVal filePath)
dim errid,errdes
On Error Resume Next
With objStream
.Type=2
.Mode=3
.Open
.Charset="gbk"
'die Server.MapPath(filePath)
.LoadFromFile Server.MapPath(filePath)
'If Err Then errid=err.number:errdes=err.description:Err.Clear:echoErr err_loadfile,errid,errdes
.Position=0
loadFile=.ReadText
.Close
End With
End Function
%>
當前名稱:ASP常用文件操作函數(shù)
文章URL:http://jinyejixie.com/news38/285588.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、自適應(yīng)網(wǎng)站、品牌網(wǎng)站制作、企業(yè)建站、網(wǎng)站內(nèi)鏈、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容