asp之FSO大全_ASP教程
推薦:asp快速分頁(yè)代碼%@ language = vbscript codepage = 936% % option explicit '強(qiáng)制定義變量 dim idcount'記錄總數(shù) dim pages'每頁(yè)條數(shù) dim pagec'總頁(yè)數(shù) dim page'頁(yè)碼 dim pagenc '每頁(yè)顯示的分頁(yè)頁(yè)碼數(shù)量=pagenc*2+1 pagenc=2 dim pagenmax '每頁(yè)顯示的分頁(yè)的最大頁(yè)碼 dim pagenmin
對(duì)于一個(gè)支持asp和fso的空間來(lái)說(shuō)有了fso一切變得簡(jiǎn)單多了
我也是個(gè)新手寫(xiě)了一些代碼供大家學(xué)習(xí)研究用
首先看支持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
'=========================================================
'◆ 根據(jù)指定名稱生成目錄
'=========================================================
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)'就建一個(gè)文件夾
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("原路徑錯(cuò)誤!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路徑錯(cuò)誤!","")
fso.CopyFile oldfile,newfile'覆蓋原來(lái)的文件
if Err.Number>0 Then call alert(Err.Description,"")
Set fso=nothing
End Function
'=========================================================
'◆ 轉(zhuǎn)移指定文件 ◆
'=========================================================
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("原路徑錯(cuò)誤!","")
newfile=Server.MapPath(newfile)
if Err.Number>0 Then call alert("新路徑錯(cuò)誤!","")
'fso.MoveFile oldfile,newfile'不能覆蓋原來(lái)的文件
fso.MoveFile "d:\o\data\test.txt","d:\o\databackup\test3.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
'=========================================================
'◆ 根據(jù)代碼生成文件 ◆
'=========================================================
'========================================
'■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
'=========================================================
'◆ 壓縮數(shù)據(jù)庫(kù) ◆
'=========================================================
'========================================
'■dbPath數(shù)據(jù)文件路徑
'■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="當(dāng)前數(shù)據(jù)庫(kù),已經(jīng)壓縮成功!"
Else
CompactDB="數(shù)據(jù)庫(kù)名稱或路徑不正確. 請(qǐng)重試!"
End If
End Function
%>
分享:Asp文件操作函數(shù)集% '===============asp 文件操作函數(shù)集1.0版本========================= ' 整理作者: 張輝 ' 程序員代號(hào):WJ008 ' 整理時(shí)間:2008年 6 月 1 日 ' 關(guān)注地址:www.wj008.net ' 所有函數(shù)使用的文件地址 全部使用絕對(duì)地址 '============================================
- asp FSO 讀寫(xiě)文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- 用ASP代碼得到客戶端IP和當(dāng)前地址
- asp中日期時(shí)間函數(shù)介紹
- 用GetString來(lái)提高ASP的速度
- 怎樣配置IIS既可以運(yùn)行ASP又可以運(yùn)行PHP
- ASP開(kāi)發(fā)中存儲(chǔ)過(guò)程應(yīng)用全接觸
- 通用獲取文章上下各三篇文章的代碼
- 使用GrapShot組件制作ASP SCRIPT計(jì)數(shù)器
- ASP程序?qū)崿F(xiàn)保存參數(shù)值的分頁(yè)功能
- 如何解決left截取字符標(biāo)題長(zhǎng)度不一
- 用ASP程序?qū)崿F(xiàn)網(wǎng)站在線人數(shù)統(tǒng)計(jì)
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-asp之FSO大全
。