詳解asp之FileSystemObject對象_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:解讀asp調(diào)用子程序教程ASP程序可通過VBScript和其他方式調(diào)用子程序。 調(diào)用使用VBScript的子程序,示例代碼: html head % subvbproc(num1,num2) response.write(num1*num2) endsub % /head body p您可以像這樣調(diào)用一個程序:/p p結(jié)果:%callvbproc(3,4)%/p p或者,像這樣:/p p結(jié)果
指定的驅(qū)動器存在嗎?本例演示如何使用DriveExists方法來探測某個驅(qū)動器是否存在。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") if fs.driveexists("c:") = true then Response.Write("驅(qū)動器 c: 存在。") Else Response.Write("驅(qū)動器 c: 不存在。") End If Response.write("<br>") if fs.driveexists("g:") = true then Response.Write("驅(qū)動器 g: 存在。") Else Response.Write("驅(qū)動器 g: 不存在。") End If set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
驅(qū)動器 c: 存在。
驅(qū)動器 g: 存在。
取得某個指定驅(qū)動器的名稱
本例演示如何使用GetDriveName方法來取得某個指定的驅(qū)動器的名稱。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") p=fs.GetDriveName("c:\windows\cursors\abc.cur") Response.Write("驅(qū)動器名稱是:" & p) set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
驅(qū)動器名稱是:c:
指定的文件存在嗎?
本例演示如何首先創(chuàng)建FileSystemObject對象,然后使用FileExists方法來探測某文件是否存在。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") If (fs.FileExists("c:\windows\cursors\xxx.cur"))=true Then Response.Write("文件 c:\windows\cursors\xxx.cur 存在。") Else Response.Write("文件 c:\windows\cursors\xxx.cur 不存在。") End If set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
文件 c:\windows\cursors\xxx.cur 不存在。
指定的文件夾存在嗎?
本例演示如何使用FolderExists方法探測某文件夾是否存在。
本示例代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") If fs.FolderExists("c:\temp") = true Then Response.Write("文件夾 c:\temp 存在。") Else Response.Write("文件夾 c:\temp 不存在。") End If set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
文件夾 c:\temp 不存在。
取得某個指定路徑的父文件夾的名稱
本例演示如何使用GetParentFolderName方法來取得某個指定的路徑的父文件夾的名稱。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur") Response.Write("c:\windows\cursors\abc.cur 的父文件夾名稱是:" & p) set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
c:\windows\cursors\abc.cur 的父文件夾名稱是:c:\winnt\cursors
取得文件夾擴(kuò)展名
本例演示如何使用GetExtensionName方法來取得指定的路徑中的最后一個成分的文件擴(kuò)展名。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write("文件 3dgarro 的文件擴(kuò)展名是:") Response.Write(fs.GetExtensionName("c:\windows\cursors\abc.cur")) set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
文件 3dgarro 的文件擴(kuò)展名是:cur
取得文件名
本例演示如何使用GetFileName方法來取得指定的路徑中的最后一個成分的文件名。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write("這個文件名的最后一個成分是:") Response.Write(fs.GetFileName("c:\windows\cursors\abc.cur")) set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
這個文件名的最后一個成分是:abc.cur
取得文件或文件夾的基名稱
本例演示如何使用GetBaseName方法來返回在指定的路徑中文件或者文件夾的基名稱。
代碼如下:
| <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") Response.Write(fs.GetBaseName("c:\windows\cursors\abc.cur")) Response.Write("<br />") Response.Write(fs.GetBaseName("c:\windows\cursors\")) Response.Write("<br />") Response.Write(fs.GetBaseName("c:\windows\")) set fs=nothing %> </body> </html> |
本實(shí)例運(yùn)行結(jié)果如下:
| abc cursors windows |
分享:解析ASP日期格式的數(shù)據(jù)加減計算方法在ASP中為我們提供了專門的日期加減函數(shù)。 1.日期相加 DateAdd函數(shù) 返回已添加指定時間間隔的日期。 DateAdd(interval,number,date) DateAdd函數(shù)的語法有以下參數(shù) (1)interval必選項(xiàng)。字符串表達(dá)式,表示要添加的時間間隔。有關(guān)數(shù)值,請參閱“設(shè)置”部分。
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-詳解asp之FileSystemObject對象
。