国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

FSO代碼詳細解析

2024-05-04 11:05:02
字體:
供稿:網(wǎng)友

  FSO是微軟ASP的一個對文件操作的控件,那么接下來就由錯新頻道的小編給小伙伴們分享一篇關(guān)于FSO代碼詳細解析吧。

  使用FSO修改文件特定內(nèi)容的函數(shù)

  functionFSOchange(filename,Target,String)

  DimobjFSO,objCountFile,FiletempData

  SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

  SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)

  FiletempData=objCountFile.ReadAll

  objCountFile.Close

  FiletempData=Replace(FiletempData,Target,String)

  SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

  objCountFile.WriteFiletempData

  objCountFile.Close

  SetobjCountFile=Nothing

  SetobjFSO=Nothing

  EndFunction

  使用FSO讀取文件內(nèi)容的函數(shù)

  functionFSOFileRead(filename)

  DimobjFSO,objCountFile,FiletempData

  SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

  SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)

  FSOFileRead=objCountFile.ReadAll

  objCountFile.Close

  SetobjCountFile=Nothing

  SetobjFSO=Nothing

  EndFunction

  使用FSO讀取文件某一行的函數(shù)

  functionFSOlinedit(filename,lineNum)

  iflinenum

  dimfso,f,temparray,tempcnt

  setfso=server.CreateObject("scripting.filesystemobject")

  ifnotfso.fileExists(server.mappath(filename))thenexitfunction

  setf=fso.opentextfile(server.mappath(filename),1)

  ifnotf.AtEndofStreamthen

  tempcnt=f.readall

  f.close

  setf=nothing

  temparray=split(tempcnt,chr(13)&chr(10))

  iflineNum>ubound(temparray)+1then

  exitfunction

  else

  FSOlinedit=temparray(lineNum-1)

  endif

  endif

  endfunction

  使用FSO寫文件某一行的函數(shù)

  functionFSOlinewrite(filename,lineNum,Linecontent)

  iflinenum

  dimfso,f,temparray,tempCnt

  setfso=server.CreateObject("scripting.filesystemobject")

  ifnotfso.fileExists(server.mappath(filename))thenexitfunction

  setf=fso.opentextfile(server.mappath(filename),1)

  ifnotf.AtEndofStreamthen

  tempcnt=f.readall

  f.close

  temparray=split(tempcnt,chr(13)&chr(10))

  iflineNum>ubound(temparray)+1then

  exitfunction

  else

  temparray(lineNum-1)=lineContent

  endif

  tempcnt=join(temparray,chr(13)&chr(10))

  setf=fso.createtextfile(server.mappath(filename),true)

  f.writetempcnt

  endif

  f.close

  setf=nothing

  endfunction

  使用FSO添加文件新行的函數(shù)

  functionFSOappline(filename,Linecontent)

  dimfso,f

  setfso=server.CreateObject("scripting.filesystemobject")

  ifnotfso.fileExists(server.mappath(filename))thenexitfunction

  setf=fso.opentextfile(server.mappath(filename),8,1)

  f.writechr(13)&chr(10)&Linecontent

  f.close

  setf=nothing

  endfunction

  讀文件最后一行的函數(shù)

  functionFSOlastline(filename)

  dimfso,f,temparray,tempcnt

  setfso=server.CreateObject("scripting.filesystemobject")

  ifnotfso.fileExists(server.mappath(filename))thenexitfunction

  setf=fso.opentextfile(server.mappath(filename),1)

  ifnotf.AtEndofStreamthen

  tempcnt=f.readall

  f.close

  setf=nothing

  temparray=split(tempcnt,chr(13)&chr(10))

  FSOlastline=temparray(ubound(temparray))

  endif

  endfunction

  FSO替換指定文件的字符

  程序代碼:

  'FSO替換指定文件的字符

  FunctionFSOLineEdit(filename,Target,String)

  DimobjFSO,objCountFile,FiletempData

  SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

  SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)

  FiletempData=objCountFile.ReadAll

  objCountFile.Close

  FiletempData=Replace(FiletempData,Target,String)

  SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

  objCountFile.WriteFiletempData

  objCountFile.Close

  SetobjCountFile=Nothing

  SetobjFSO=Nothing

  EndFunction

  'Response.WriteFSOLineEdit("test.txt","世界","明天是一個好天去")

  刪除文件

  程序代碼:

  '刪除文件

  FunctionDelFile(Filename)

  IfFilename""Then

  SetFSO=Server.CreateObject("Scripting.FileSystemObject")

  IfFSO.FileExists(Filename)Then

  FSO.DeleteFileFilename

  EndIf

  SetFSO=Nothing

  EndIf

  EndFunction

  判斷文件是否存在

  程序代碼:

  '判斷文件是否存在

  FunctionReportFileStatus(filespec)

  DimFSO,msg

  SetFSO=CreateObject("Scripting.FileSystemObject")

  If(FSO.FileExists(filespec))Then

  msg=filespec&"exists."

  Else

  msg=filespec&"doesn'texist."

  EndIf

  ReportFileStatus=msg

  EndFunction

  使用FSO修改文件特定內(nèi)容的函數(shù)

  程序代碼:

  '使用FSO修改文件特定內(nèi)容的函數(shù)

  FunctionFSOchange(filename,Target,String)

  DimobjFSO,objCountFile,FiletempData

  SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")

  SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)

  FiletempData=objCountFile.ReadAll

  objCountFile.Close

  FiletempData=Replace(FiletempData,Target,String)

  SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)

  objCountFile.WriteFiletempData

  objCountFile.Close

  SetobjCountFile=Nothing

  SetobjFSO=Nothing

  EndFunction

  使用FSO寫文件某一行的函數(shù)

  程序代碼:

  '使用FSO寫文件某一行的函數(shù)

  FunctionFSOlinewrite(filename,lineNum,Linecontent)

  Iflinenum

  DimFSO,f,temparray,tempCnt

  SetFSO=Server.CreateObject("Scripting.FileSystemObject")

  IfNotFSO.FileExists(Server.MapPath(filename))ThenExitFunction

  Setf=FSO.OpenTextFile(Server.MapPath(filename),1)

  IfNotf.AtEndofStreamThen

  tempcnt=f.ReadAll

  f.Close

  temparray=Split(tempcnt,Chr(13)&Chr(10))

  IflineNum>UBound(temparray)+1Then

  ExitFunction

  Else

  temparray(lineNum-1)=lineContent

  EndIf

  tempcnt=join(temparray,Chr(13)&Chr(10))

  Setf=FSO.createtextfile(Server.MapPath(filename),true)

  f.Writetempcnt

  EndIf

  f.Close

  Setf=Nothing

  EndFunction

  建立目錄的程序,如果有多級目錄,則一級一級的創(chuàng)建

  程序代碼:

  '建立目錄的程序,如果有多級目錄,則一級一級的創(chuàng)建

  FunctionCreateDIR(ByValLocalPath)

  OnErrorResumeNext

  LocalPath=Replace(LocalPath,"/","/")

  SetFileObject=Server.CreateObject("Scripting.FileSystemObject")

  patharr=Split(LocalPath,"/")

  path_level=UBound(patharr)

  Fori=0topath_level

  Ifi=0Thenpathtmp=patharr(0)&"/"Elsepathtmp=pathtmp&patharr(i)&"/"

  cpath=Left(pathtmp,Len(pathtmp)-1)

  IfNotFileObject.FolderExists(cpath)ThenFileObject.CreateFoldercpath

  Next

  SetFileObject=Nothing

  IfErr.Number0Then

  CreateDIR=False

  Err.Clear

  Else

  CreateDIR=True

  EndIf

  EndFunction

  下面列舉一下這些不常用但是卻非常酷的功能:

  很少被了解的FSO功能

  GetSpecialFolderMethod返回特定的Windows文件夾的路徑:Windows安裝目錄;Windows系統(tǒng)目錄;Windows臨時目錄FSO.GetSpecialFolder([0,1,or2])

  GetTempNameMethod返回一個隨機產(chǎn)生的文件或者目錄名字,用于需要存儲臨時數(shù)據(jù)時

  GetAbsolutePathNameMethod返回文件夾的絕對路徑(類似于Server.MapPath)。

  比如,F(xiàn)SO.GetAbsolutePathName("region")將返回類似于下面的結(jié)果:"c:mydocsmyfolderegion"

  GetExtensionNameMethod返回路徑中最后部分的擴展名

  (比如:FSO.GetExtensionName("c:docsest.txt")將返回txt)

  GetBaseNameandGetParentFolderMethods返回路徑中最后部分的父文件夾

  (比如:FSO.GetParentFolder("c:docsmydocs")將返回'docs')

  DrivesProperty返回所有本地可用驅(qū)動器的集合,用于建立資源瀏覽器樣的用戶接口。

  使用上面的功能時,最好建立好出錯處理的代碼。因為如果需要的參數(shù)不存在,將會產(chǎn)生麻煩的信息。

  以上就是關(guān)于FSO代碼詳細解析了,想必都了解了吧,更多相關(guān)內(nèi)容請繼續(xù)關(guān)注錯新技術(shù)頻道。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东港市| 无极县| 阳谷县| 宝坻区| 六安市| 印江| 岐山县| 河北区| 广昌县| 蓝田县| 新昌县| 邢台市| 平武县| 龙泉市| 宜昌市| 荆门市| 北票市| 灵石县| 佛学| 吕梁市| 北辰区| 四川省| 渝北区| 昌邑市| 绥芬河市| 正镶白旗| 图片| 长垣县| 汽车| 宣恩县| 淳化县| 延庆县| 天津市| 克什克腾旗| 同仁县| 镇巴县| 武陟县| 台北市| 色达县| 襄垣县| 揭东县|