99re热视频精品首页-99re热视频在线-99re热视频这里只有精品5-99re热线精品视频-99re热在线观看-99re热在线视频

蒙狼科技logo
設(shè)為首頁| 聯(lián)系我們
咨詢熱線: 13917498722
  您的位置: 首頁 > 網(wǎng)站資訊 > ASP常用文件操作函數(shù)

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

發(fā)布日期:2017/3/7
以下包含了常用的各種ASP常用文件操作函數(shù):如創(chuàng)建一個指定的文件,建立文件目錄,檢查文件是否存在,刪除文件目錄,移動刪除文件,讀取文件內(nèi)容等
<%
'創(chuàng)建一個指定的文件函數(shù),可選參數(shù),文件內(nèi)容,文件目錄與文件生成類型
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

'讀取文件內(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
%>





其他相關(guān)文章
  • 公益性網(wǎng)站制作的注意事項
  • SEO網(wǎng)站談談知名度對網(wǎng)站建設(shè)的影響
  • SEOer 常常碰到的一些問題-網(wǎng)站建設(shè)總結(jié)
  • 什么樣的網(wǎng)站更容易的到用戶青睞
  • 企業(yè)為什么需要建設(shè)網(wǎng)站及建站要準備哪些資料?
  • 推薦7款超棒的免費單頁面網(wǎng)站設(shè)計模板




  • 企業(yè)網(wǎng)站后臺使用
    購物網(wǎng)站后臺使用
    網(wǎng)站產(chǎn)品圖片的處理



    農(nóng)業(yè)銀行支付
    建設(shè)銀行支付
    郵政儲蓄銀行支付



    企業(yè)網(wǎng)站建設(shè)
    整站建設(shè)
    購物網(wǎng)站



    企業(yè)網(wǎng)站建設(shè)建議
    注冊適合自己的域名
    什么是虛擬主機




    售前咨詢QQ: 838821345
    售后服務QQ: 464698733
    應急手機:13917498722


    微信掃一掃
    添加24小時微信客服


    郵箱:lang@MENGL.CN
    地址:上海寶山區(qū)城銀路555弄2號樓3樓
    ICP備案:滬ICP備12042844號-3
     滬公網(wǎng)安備:31011402002917號
    做網(wǎng)站 | 企業(yè)網(wǎng)站建設(shè) | 上海做網(wǎng)站 | 企業(yè)網(wǎng)站制作 | 做網(wǎng)站的公司 | 關(guān)于蒙狼 | 整站建設(shè) | 購物網(wǎng)站 | 企業(yè)網(wǎng)絡營銷 | 成功案例 | 加盟代理 | 在線訂單
    服務區(qū)域: 臨港新區(qū)做網(wǎng)站 徐匯做網(wǎng)站 閔行做網(wǎng)站 長寧做網(wǎng)站 虹口做網(wǎng)站 黃浦做網(wǎng)站 盧灣做網(wǎng)站 靜安做網(wǎng)站 浦東做網(wǎng)站 楊浦做網(wǎng)站 普陀做網(wǎng)站 閘北做網(wǎng)站 寶山做網(wǎng)站 嘉定做網(wǎng)站 松江做網(wǎng)站 昆山做網(wǎng)站
    Copyright 2012-2025 上海蒙狼網(wǎng)絡科技有限公司 www.zcrhy.com.cn All Rights Reserved