**************************************************
'函數名稱:FSOFileRead
'作用:使用FSO讀取檔案內容的函數
'參數:filename ----檔案名稱
'傳回值:文件內容
'************************************************* *
function FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject(Scripting.FileSystemObject)
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function
'************************************************* *
'函數名稱:FSOlinedit
'作用:使用FSO讀取檔案某一行的函數
'參數:filename ----檔案名稱
' lineNum ----行數
'傳回值:文件該行內容
'************************************************* *
function FSOlinedit(filename,lineNum)
if linenum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject(scripting.filesystemobject)
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
FSOlinedit = temparray(lineNum-1)
end if
end if
end function
'************************************************* *
'函數名稱:FSOlinewrite
'作用:使用FSO寫入檔案某一行的函數
'參數:filename ----檔案名稱
' lineNum ----行數
' Linecontent ----內容
'傳回值:無
'************************************************* *
function FSOlinewrite(filename,lineNum,Linecontent)
if linenum < 1 then exit function
dim fso,f,temparray,tempCnt
set fso = server.CreateObject(scripting.filesystemobject)
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
temparray(lineNum-1) = lineContent
end if
tempcnt = join(temparray,chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename),true)
f.write tempcnt
end if
f.close
set f = nothing
end function