ASP FSO文件處理函數(shù)大全
直接上代碼
<% '建立文件夾函數(shù) Function CreateFolder(strFolder)'參數(shù)為相對(duì)路徑 '首選判斷要建立的文件夾是否已經(jīng)存在 Dim strTestFolder,objFSO strTestFolder = Server.Mappath(strFolder) Set objFSO = CreateObject("Scripting.FileSystemObject") '檢查文件夾是否存在 If not objFSO.FolderExists(strTestFolder) Then '如果不存在則建立文件夾 objFSO.CreateFolder(strTestFolder) End If Set objFSO = Nothing End function '刪除文件夾 Function DelFolder(strFolder)'參數(shù)為相對(duì)路徑 strTestFolder = Server.Mappath(strFolder) Set objFSO = CreateObject("Scripting.FileSystemObject") '檢查文件夾是否存在 If objFSO.FolderExists(strTestFolder) Then objFSO.DeleteFolder(strTestFolder) end if Set objFSO = Nothing End function '創(chuàng)建文本文件 Function Createtextfile(fileurl,filecontent)'參數(shù)為相對(duì)路徑和要寫入文件的內(nèi)容 Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set fout = objFSO.CreateTextFile(Server.MapPath(fileurl)) fout.WriteLine filecontent fout.close Set objFSO = Nothing End Function '刪除文件(適合所有文件) Function Deltextfile(fileurl)'參數(shù)為相對(duì)路徑 Set objFSO = CreateObject("Scripting.FileSystemObject") fileurl = Server.MapPath(fileurl) if objFSO.FileExists(fileurl) then '檢查文件是否存在 objFSO.DeleteFile(Server.mappath(fileurl)) end if Set objFSO = nothing End Function '建立圖片文件并保存圖片數(shù)據(jù)流 Function Createimage(fileurl,imagecontent)'參數(shù)為相對(duì)路徑和文件內(nèi)容 Set objStream = Server.CreateObject("ADODB.Stream") '建立ADODB.Stream對(duì)象,必須要ADO 2.5以上版本 objStream.Type =1 '以二進(jìn)制模式打開 objStream.Open objstream.write imagecontent '將字符串內(nèi)容寫入緩沖 objstream.SaveToFile server.mappath(fileurl),2 '-將緩沖的內(nèi)容寫入文件 objstream.Close()'關(guān)閉對(duì)象 set objstream=nothing End Function '遠(yuǎn)程獲取文件數(shù)據(jù) Function getHTTPPage(url) 'On Error Resume Next dim http set http=Server.createobject("Microsoft.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") set http=nothing If Err.number<>0 then getHTTPPage = "服務(wù)器獲取文件內(nèi)容出錯(cuò)" Err.Clear End If End function Function BytesToBstr(body,Cset) dim objstream set objstream = Server.CreateObject("adodb.stream") objstream.Type = 1 objstream.Mode =3 objstream.Open objstream.Write body objstream.Position = 0 objstream.Type = 2 objstream.Charset = Cset BytesToBstr = objstream.ReadText objstream.Close set objstream = nothing End Function '獲取圖片數(shù)據(jù)流 Function getpic(url) on error resume next dim http set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法來獲得圖片的內(nèi)容 Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if getpic=Http.responseBody set http=nothing if err.number<>0 then getpic = "服務(wù)器獲取文件內(nèi)容出錯(cuò)" err.Clear End if End Function '打開文件(文本形式) Function OpenFile(fileurl)'文件相對(duì)路徑 Dim Filename,fso,hndFile Filename = fileurl Filename = Server.MapPath(Filename) Set objfso = CreateObject("Scripting.FileSystemObject") If objfso.FileExists(Filename) Then set hndFile = objfso.OpenTextFile(Filename) OpenFile = hndFile.ReadAll Else OpenFile = "文件讀取錯(cuò)誤" End If Set hndFile = Nothing Set objfso = Nothing End Function '獲得文件的后綴名 function getFileExtName(fileName) dim pos pos=instrrev(filename,".") if pos>0 then getFileExtName=mid(fileName,pos+1) else getFileExtName="" end if end function Dim fso,f,folder Set fso=Server.CreateObject("scripting.filesystemobject") '改目錄名 Set folder=fso.getfolder(Server.Mappath("Old")) folder.name="New" '新名字 '改文件名 Set f=fso.getfile(Server.Mappath("Old.asp")) f.name="New.asp" '新名字 '釋放 function copyfile(l1,l2)'復(fù)制文件 on error resume next dim fs set fs=createobject("Scripting.FileSystemObject") fs.copyfile server.mappath(l1),server.mappath(l2) set fs=nothing if err.number<>0 then err.clear end function copyfile("db1.mdb","db2.mdb")
具體的大家可以搜索
FSO操作全集
下面的代碼也適合vbs
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso 變量調(diào)用 getfso=fso.DriveExists("g:\") '判斷指定硬盤驅(qū)動(dòng)器是否存在 getfso=fso.GetDrive("c:") '創(chuàng)建自定義的FSO驅(qū)動(dòng)器對(duì)象 getfso=fso.GetDriveName("c:\網(wǎng)絡(luò)程序員伴侶") '返回文件夾的所在盤符 Set getfso=fso.Drives '創(chuàng)建FSO驅(qū)動(dòng)器集合對(duì)象,多配合for each i in getfso語句進(jìn)行窮盡操作,支持所有[驅(qū)動(dòng)器對(duì)象屬性],并具有Count和Item屬性 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
驅(qū)動(dòng)器對(duì)象操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 getfso=fso.GetDrive("c:").FileSystem '返回驅(qū)動(dòng)器對(duì)象的文件系統(tǒng)類型 getfso=fso.GetDrive("c:").DriveType '返回驅(qū)動(dòng)器對(duì)象的驅(qū)動(dòng)器類型,返回值范圍0-5 getfso=fso.GetDrive("c:").DriveLetter '返回驅(qū)動(dòng)器對(duì)象的字母 getfso=fso.GetDrive("c:").IsReady '返回指定驅(qū)動(dòng)器是否準(zhǔn)備好或是否損壞 getfso=fso.GetDrive("c:").SerialNumber '返回驅(qū)動(dòng)器對(duì)象的唯一十進(jìn)制卷標(biāo)序號(hào) getfso=fso.GetDrive("c:").ShareName '返回驅(qū)動(dòng)器對(duì)象的網(wǎng)絡(luò)共享名 getfso=fso.GetDrive("c:").VolumeName '返回驅(qū)動(dòng)器對(duì)象的卷標(biāo)名,同時(shí)也可以設(shè)置其卷標(biāo)名 getfso=fso.GetDrive("c:").Path '返回驅(qū)動(dòng)器的實(shí)際路徑,如c:\則返回c: getfso=fso.GetDrive("c:").RootFolder '返回驅(qū)動(dòng)器對(duì)象的跟文件夾 getfso=fso.GetDrive("c:").AvailableSpace'返回驅(qū)動(dòng)器對(duì)象的可用容量大小 getfso=fso.GetDrive("c:").FreeSpace '返回驅(qū)動(dòng)器對(duì)象的剩余空間大小 getfso=fso.GetDrive("c:").TotalSize '返回驅(qū)動(dòng)器對(duì)象的總空間容量大小 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
系統(tǒng)文件夾操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 getfso=fso.GetFolder("c:\") '創(chuàng)建自定義的FSO文件夾對(duì)象 getfso=fso.FolderExists("e:\網(wǎng)絡(luò)程序員伴侶") '判斷指定文件夾是否存在 getfso=fso.GettempName '隨機(jī)返回WINDOW產(chǎn)生在temp文件夾中的臨時(shí)文件 getfso=fso.GetparentFolderName("e:\網(wǎng)絡(luò)程序員伴侶") '返回指定文件夾的父文件夾 fso.CreateFolder "c:\windows\新創(chuàng)建的文件夾路徑及名稱" fso.MoveFolder "c:\windows\許移動(dòng)或改名的文件夾","c:\windows\移動(dòng)路徑和新的文件夾名" fso.DeleteFolder "c:\windows\要?jiǎng)h除的目錄名",false/true fso.CopyFolder "c:\windows\須復(fù)制的目錄名","c:\windows\得到付值內(nèi)容的目錄名",false/true Set getfso=fso.Folders '創(chuàng)建FSO文件夾集合對(duì)象,多配合for each i in getfso語句進(jìn)行窮盡操作,支持所有[文件夾對(duì)象屬性],并具有Count和Item屬性,具有AddFolders方法 Set getfso=fso.Files '創(chuàng)建FSO文件夾內(nèi)文件集合對(duì)象,多配合for each i in getfso語句進(jìn)行窮盡操作,支持所有[文件對(duì)象屬性],并具有Count和Item屬性 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
文件夾對(duì)象操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 getfso=fso.GetFolder("c:\windows").Name '返回文件夾的名字,這里返回WINDOW getfso=fso.GetFolder("c:\windows").ShortName '返回文件夾[8.3]格式的名稱 getfso=fso.GetFolder("c:\windows").Attributes '返回文件夾的屬性,可返回0,1,2,4,8,16,32,64,128 getfso=fso.GetFolder("c:\windows").Size '返回文件夾(包括子文件夾)內(nèi)文件占用空間大小 getfso=fso.GetFolder("c:\windows").Type '返回文件夾類型信息 getfso=fso.GetFolder("c:\windows").Path '返回文件夾的真實(shí)路徑 getfso=fso.GetFolder("c:\windows").ShortPath '返回文件夾[8.3]格式的路徑 getfso=fso.GetFolder("c:\windows").Drive '返回文件夾所在驅(qū)動(dòng)器 getfso=fso.GetFolder("c:\windows").Files.count '返回文件夾包含的所有文件對(duì)象集合 getfso=fso.GetFolder("c:\windows").SubFolders.count '返回文件夾包含的所有子文件夾的對(duì)象集合 getfso=fso.GetFolder("c:\windows").ParentFolder '返回文件夾的父文件夾對(duì)象 getfso=fso.GetFolder("c:\windows").IsRootFolder '返回文件夾是否為跟文件夾,是返回true否返回false getfso=fso.GetFolder("c:\windows").DateCreated '返回文件夾的最初創(chuàng)建時(shí)間 getfso=fso.GetFolder("c:\windows").DateLastAccessed '返回文件夾最后一次訪問時(shí)間 getfso=fso.GetFolder("c:\windows").DateLastModified '返回文件夾最近修改的時(shí)間 fso.GetFolder("c:\windows").CreateTextFile "新建的文件名及后綴",true/false,true/false fso.GetFolder("c:\windows\要?jiǎng)h除的目錄名").Delete true fso.GetFolder("c:\windows\要移動(dòng)改名的目錄名").Move "文件夾將要移動(dòng)到的路徑及自定義文件夾名稱" fso.GetFolder("c:\windows\舊目錄").Copy "復(fù)制到路徑",true/false '在指定路徑付值此文件夾,true=覆蓋,false相反 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
系統(tǒng)文件操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 getfso=fso.GetFile("c:\windows\help.html") '得到文件完整路徑 getfso=fso.GetFileName("c:\windows\help.html") '得到文件名稱和后綴 getfso=fso.GetExtensionName("c:\windows\help.html") '得到文件的文件類型(后綴),不含小數(shù)點(diǎn) getfso=fso.FileExists("c:\windows\文件名.html") '判斷文件是否存在 fso.MoveFile "要移動(dòng)及改名的原文件路徑","移動(dòng)到某路徑及自定義新文件名" fso.DeleteFile "c:\windows\要?jiǎng)h除的文件所在路徑",false/true fso.CopyFile "c:\windows\須復(fù)制的舊文件.txt","c:\windows\復(fù)制后的文件名.jpg",false/true fso.OpenTextFile "c:\windows\desktop\要打開操作的文件名稱.txt",1/2/8,true/false,0/-1/-2 'ForReading=1=只讀方式,ForWriting=2=可寫方式,ForAppending=8=追加方式.true=如果打開的文件不存在則創(chuàng)建該文件.TristateFalse=0=以系統(tǒng)默認(rèn)方式打開,TristateTrue=-1=以Unicode格式打開文件,TristateUseDefaule=-2=以ASCLL格式打開文件(缺剩值) fso.CreateTextFile "c:\windows\desktop\新建的文件名稱.txt",false/true,false/true '前者true覆蓋以存在同名文件,后者為true新文件將以Unicode方式創(chuàng)建,反之=結(jié)果相反 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
文件對(duì)象操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 getfso=fso.GetFile("c:\windows\筆記本.txt").Name '返回文件對(duì)象的名稱包含后綴 getfso=fso.GetFile("c:\windows\筆記本.txt").ShortName '返回文件對(duì)象的[8.3]名稱包含后綴 getfso=fso.GetFile("c:\windows\筆記本.txt").Attributes '返回文件對(duì)象的屬性,可返回0,1,2,4,8,16,32,64,128 getfso=fso.GetFile("c:\windows\筆記本.txt").Size '返回文件對(duì)象的大小 getfso=fso.GetFile("c:\windows\筆記本.txt").Type '返回文件對(duì)象的類型 getfso=fso.GetFile("c:\windows\筆記本.txt").Path '返回文件對(duì)象的完整路徑 getfso=fso.GetFile("c:\windows\筆記本.txt").ShortPath '返回文件對(duì)象的[8.3]的完整路徑 getfso=fso.GetFile("c:\windows\筆記本.txt").Drive '返回此文件對(duì)象所在的驅(qū)動(dòng)器 getfso=fso.GetFile("c:\windows\筆記本.txt").ParentFolder '返回文件對(duì)象所在的文件夾 getfso=fso.GetFile("c:\windows\筆記本.txt").DateCreated '返回文件對(duì)象的創(chuàng)建日期 getfso=fso.GetFile("c:\windows\筆記本.txt").DateLastAccessed '返回文件對(duì)象的最后訪問日期 getfso=fso.GetFile("c:\windows\筆記本.txt").DateLastModified '返回文件對(duì)象的最后修改時(shí)間 fso.GetFile("c:\windows\筆記本.txt").Copy "復(fù)制到的路徑和文件名",true/false fso.GetFile("c:\windows\筆記本.txt").Delete true fso.GetFile("c:\windows\筆記本.txt").Move "移動(dòng)到的路徑及自定義文件名 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
文件對(duì)象讀寫操作
<script language=vbs> on error resume next Set fso=CreateObject("Scripting.FileSystemObject") '使FSO組件可以被fso變量調(diào)用 set link1=fso.GetFile("c:\windows\筆記本.txt").OpenAsTextStream(1/2/8,0/-1/-2) open1=link1.AtendOfline '判斷文件指針是否以在行的末尾 open2=link1.AtendOfstream '判斷文件指針是否一再文件的末尾 open3=link1.Column '返回當(dāng)前字符所在文件的列號(hào) open4=link1.Line '返回當(dāng)前字符所在文件的行號(hào) open5=link1.Read(10) '讀取文件中指定數(shù)量的字符 open6=link1.ReadAll '讀取文件中所有的字符 open7=link1.ReadLine '讀取文件中一行中含有的字符 open8=link1.Write "字符串" '將自定字符串或字符串變量寫入文件 open9=link1.WriteLine "字符" '將自定字符+一個(gè)換行符寫入文件 open10=link1.WriteBlankLines 10 '將指定數(shù)量的換行符寫入文件 open11=link1.Skip 10 '使文件指針跳過指定數(shù)量的字符 open12=link1.SkipLine '使文件指針跳到下一行 link1.Close '文件操作完畢,銷毀文件對(duì)象指針 Set fso=Nothing '釋放fso變量與FSO組件的連接資源 </script>
以上就是ASP FSO文件處理函數(shù)大全的詳細(xì)內(nèi)容,更多關(guān)于ASP FSO文件處理的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- asp中通過fso讀取和生成UTF-8編碼的txt
- ASP FSO文件操作函數(shù)代碼(復(fù)制文件、重命名文件、刪除文件、替換字符串)
- asp fso操作類
- ASP+FSO生成的網(wǎng)頁文件默認(rèn)編碼格式以及轉(zhuǎn)換成UTF-8編碼方法
- asp下用fso和ado.stream寫xml文件的方法
- asp結(jié)合fso實(shí)現(xiàn)文件或文件夾創(chuàng)建刪除等操作的函數(shù)
- asp下用fso生成js文件的代碼
- asp下利用fso實(shí)現(xiàn)文件夾或文件移動(dòng)改名等操作函數(shù)
- fso asp生成靜態(tài)html的代碼
- ASP+FSO可視化目錄編歷(可增、刪、改)下載
- asp下用ADODB.Stream代替FSO讀取文本文件
- asp利用fso給文件夾和文件改名的代碼
- 結(jié)合FSO操作和Aspjpeg組件寫的Class
- ASP使用FSO讀取模板的代碼
- asp中FSO復(fù)制文件代碼
相關(guān)文章
ASP基礎(chǔ)入門第九篇(Global.asa文件的使用)
這篇文章主要介紹了Global.asa文件的使用,是一個(gè)可選文件,每個(gè)應(yīng)用程序只能有一個(gè) Global.asa 文件,需要了解的朋友可以參考下2015-10-10Microsoft VBScript 編譯器錯(cuò)誤 錯(cuò)誤原因 代碼大全
這篇文章主要介紹了Microsoft VBScript 編譯器錯(cuò)誤 錯(cuò)誤原因 代碼大全,需要的朋友可以參考下2015-07-07改進(jìn)一下asp自帶的formatNumber函數(shù)
改進(jìn)一下asp自帶的formatNumber函數(shù)...2006-08-08asp 動(dòng)態(tài)生成rss(不成生xml文件)代碼
為你的網(wǎng)站添加rss閱讀功能 把以下文件保存為 rss.asp 放在網(wǎng)站的根目錄下 修改里面的幾個(gè)參數(shù)就可以2008-12-12asp對(duì)復(fù)雜json的解析一定要注意要點(diǎn)
網(wǎng)上有很多類似的文章但只解析出第一層,后面的死活試了大半天才測試出來,下面貼上我的代碼,解釋一下,也算對(duì)我做的東西留個(gè)備份2014-06-06