中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

ASP常用文件操作函數(shù)

2023-10-11    分類: 網站建設

以下包含了常用的各種ASP常用文件操作函數(shù):如創(chuàng)建一個指定的文件,建立文件目錄,檢查文件是否存在,刪除文件目錄,移動刪除文件,讀取文件內容等
<%
'創(chuàng)建一個指定的文件函數(shù),可選參數(shù),文件內容,文件目錄與文件生成類型
Function createTextFile(Byval content,Byval fileDir,Byval code)
dim fileobj,fileCode : fileDir=replace(fileDir, "\", "/")
if isNul(code) then fileCode="gbk" else fileCode=code
call createfolder(fileDir,"filedir")
on error resume next:err.clear
set fileobj=objFso.CreateTextFile(server.mappath(fileDir),True)
fileobj.Write(content)
set fileobj=nothing
if Err or not isNul(code) then
err.clear
With objStream
.Charset=fileCode:.Type=2:.Mode=3:.Open:.Position=0
.WriteText content:.SaveToFile Server.MapPath(fileDir), 2
.Close
End With
end if
if Err Then  createTextFile=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_writefile,errid,errdes else createTextFile=true
End Function

'建立文件存儲對象函數(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

'讀取文件內容函數(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://www.rwnh.cn/news38/285588.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供域名注冊自適應網站、品牌網站制作企業(yè)建站、網站內鏈、動態(tài)網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網站托管運營
当阳市| 隆昌县| 翁牛特旗| 天长市| 合山市| 龙游县| 增城市| 溧水县| 巨野县| 湛江市| 庆阳市| 邛崃市| 余庆县| 太仆寺旗| 新宾| 威信县| 高州市| 镇巴县| 乌兰察布市| 三亚市| 黑水县| 义乌市| 兰溪市| 全州县| 平遥县| 萨迦县| 繁峙县| 大悟县| 昭通市| 吴旗县| 南丰县| 长顺县| 剑川县| 桐乡市| 神农架林区| 葫芦岛市| 高安市| 巴青县| 宾阳县| 靖边县| 英德市|