asp之FSO大全

來源:互聯網
上載者:User

  對於一個支援asp和fso的空間來說有了fso一切變得簡單多了

我也是個新手寫了一些代碼供大家學習研究用

首先看支援fso組件嗎

<%
'FSO組件名稱
dim FSObject
FSObject="Scripting.FileSystemObject"

'=========================================================
'◆是否支援組件
'=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function

if IsObjInstalled(FSObject) then
response.write "√"
else
response.write "×"
end if%>
-------------------------------------------------------
<%
'=========================================================
'◆是否支援組件
'=========================================================
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
'=========================================================
'fso 操作
'=========================================================
'◆檢查某一目錄是否存在
'=========================================================
Function CheckDir(FolderPath)
folderpath=Server.MapPath(".")&""&folderpath
Set fso= CreateObject(FSObject)
If fso.FolderExists(FolderPath) then
CheckDir = True
Else
CheckDir = False
End if
Set fso= nothing
End Function
'=========================================================
'◆ 根據指定名稱組建目錄
'=========================================================
Function MakeNewsDir(foldername)
dim fs0
Set fso= CreateObject(FSObject)
Set fs0= fso.CreateFolder(foldername)
Set fso = nothing
End Function
'=========================================================
'◆ 如果檔案夾不存在則建立新檔案夾 ◆
'=========================================================
Function checkFolder(folderpath)
If CheckDir(folderpath) = false Then'如果檔案夾不存在
MakeNewsDir(folderpath)'就建一個檔案夾
end if
end Function
'=========================================================
'◆ 刪除檔案夾 ◆
'=========================================================
Function DeleteFoldera(folderpath)
dim path
Set fso = CreateObject(FSObject)
path=request.ServerVariables("APPL_PHYSICAL_PATH")&folderpath
fso.DeleteFolder(path)
Set fso = nothing
end Function
'=========================================================
'◆ 變更檔夾名稱 ◆
'=========================================================
Function moveFolder(foldername,newfoldername)
isfso
Set fso = CreateObject(FSObject)
fso.moveFolder ""&request.ServerVariables("APPL_PHYSICAL_PATH")&""&foldername&"" ,""&request.ServerVariables("APPL_PHYSICAL_PATH")&""&newfoldername&""
Set fso =nothing
End Function
'=========================================================
'◆ 刪除指定檔案 ◆
'=========================================================
Function DeleteFile(file)
Set fso = CreateObject(FSObject)
fso.DeleteFile request.ServerVariables("APPL_PHYSICAL_PATH")&file
Set fso = nothing
End Function
'=========================================================
'◆ 備份指定檔案 ◆
'=========================================================
Function CopyFile(oldfile,newfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=Server.CreateObject(FSObject)
oldfile=Server.MapPath(oldfile)
if Err.Number>0 Then call alert("原路徑錯誤!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路徑錯誤!","")
fso.CopyFile oldfile,newfile'覆蓋原來的檔案
if Err.Number>0 Then call alert(Err.Description,"")
Set fso=nothing
End Function
'=========================================================
'◆ 轉移指定檔案 ◆
'=========================================================
Function MoveFile(oldfile,newfile)
Set fso = CreateObject(FSObject)
On Error Resume Next
Set fso=Server.CreateObject(FSObject)
oldfile=Server.MapPath(oldfile)
if Err.Number>0 Then call alert("原路徑錯誤!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路徑錯誤!","")
'fso.MoveFile oldfile,newfile'不能覆蓋原來的檔案
fso.MoveFile "d:odatatest.txt","d:odatabackuptest3.txt"
if Err.Number>0 Then call alert(Err.Description,"")
Set fso=nothing
End Function
'=========================================================
'◆ 讀取檔案代碼 ◆
'=========================================================
Function loadfile(file)'讀取檔案
dim ftemp
Set fso = CreateObject(FSObject)
Set ftemp=fso.OpenTextFile(Server.MapPath(""&file&""), 1)
loadfile=ftemp.ReadAll
ftemp.Close
fso.close
set fso=nothing
End Function
'=========================================================
'◆ 根據代碼組建檔案 ◆
'=========================================================
'========================================
'■file組建檔案名
'■code檔案的代碼
'========================================
Function savefile(file,code)'儲存檔案
dim MyFile
Set fso = CreateObject(FSObject)
Set MyFile = fso.CreateTextFile(Server.mapPath(file), True)
MyFile.WriteLine(code)
MyFile.Close
set MyFile=nothing
End Function
'=========================================================
'◆ 壓縮資料庫 ◆
'=========================================================
'========================================
'■dbPath資料檔案路徑
'■boolIs97 access97壓縮
'========================================
Function CompactDB(dbPath,boolIs97)
dim strDBPath,fso,Engine
dbPath=server.mappath(dbpath)
strDBPath = left(dbPath,instrrev(DBPath,""))
Set fso = CreateObject(FSObject)
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
If boolIs97 = "True" Then
dim JET_3X
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
&"Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database password="&dbpw&";Data Source="&strDBPath&"temp.mdb"
End If
fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath&"temp.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB="當前資料庫,已經壓縮成功!"
Else
CompactDB="資料庫名稱或路徑不正確. 請重試!"
End If
End Function
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.