推薦:解讀asp調用子程序教程ASP程序可通過VBScript和其他方式調用子程序。 調用使用VBScript的子程序,示例代碼: html head % subvbproc(num1,num2) response.write(num1*num2) endsub % /head body p您可以像這樣調用一個程序:/pp結果:%callvbproc(3,4)%/pp或者,像這樣:/pp結果
指定的驅動器存在嗎?本例演示如何使用DriveExists方法來探測某個驅動器是否存在。代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) iffs.driveexists(c:)=truethen Response.Write(驅動器c:存在。) Else Response.Write(驅動器c:不存在。) EndIf Response.write(<br>) iffs.driveexists(g:)=truethen Response.Write(驅動器g:存在。) Else Response.Write(驅動器g:不存在。) EndIf setfs=nothing %> </body> </html> |
本實例運行結果如下:
驅動器c:存在。
驅動器g:存在。
取得某個指定驅動器的名稱
本例演示如何使用GetDriveName方法來取得某個指定的驅動器的名稱。
代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) p=fs.GetDriveName(c:/windows/cursors/abc.cur) Response.Write(驅動器名稱是:&p) setfs=nothing %> </body> </html> |
本實例運行結果如下:
驅動器名稱是:c:
指定的文件存在嗎?
本例演示如何首先創建FileSystemObject對象,然後使用FileExists方法來探測某文件是否存在。
代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) If(fs.FileExists(c:/windows/cursors/xxx.cur))=trueThen Response.Write(文件c:/windows/cursors/xxx.cur存在。) Else Response.Write(文件c:/windows/cursors/xxx.cur不存在。) EndIf setfs=nothing %> </body> </html> |
本實例運行結果如下:
文件c:/windows/cursors/xxx.cur不存在。
指定的文件夾存在嗎?
本例演示如何使用FolderExists方法探測某文件夾是否存在。
本示例代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) Iffs.FolderExists(c:/temp)=trueThen Response.Write(文件夾c:/temp存在。) Else Response.Write(文件夾c:/temp不存在。) EndIf setfs=nothing %> </body> </html> |
本實例運行結果如下:
文件夾c:/temp不存在。
取得某個指定路徑的父文件夾的名稱
本例演示如何使用GetParentFolderName方法來取得某個指定的路徑的父文件夾的名稱。
代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) p=fs.GetParentFolderName(c:/winnt/cursors/3dgarro.cur) Response.Write(c:/windows/cursors/abc.cur的父文件夾名稱是:&p) setfs=nothing %> </body> </html> |
本實例運行結果如下:
c:/windows/cursors/abc.cur的父文件夾名稱是:c:/winnt/cursors
取得文件夾擴展名
本例演示如何使用GetExtensionName方法來取得指定的路徑中的最後一個成分的文件擴展名。
代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) Response.Write(文件3dgarro的文件擴展名是:) Response.Write(fs.GetExtensionName(c:/windows/cursors/abc.cur)) setfs=nothing %> </body> </html> |
本實例運行結果如下:
文件3dgarro的文件擴展名是:cur
取得文件名
本例演示如何使用GetFileName方法來取得指定的路徑中的最後一個成分的文件名。
代碼如下:
| <html> <body> <% Setfs=Server.CreateObject(Scripting.FileSystemObject) Response.Write(這個文件名的最後一個成分是:) Response.Write(fs.GetFileName(c:/windows/cursors/abc.cur)) setfs=nothing %> </body> </html> |
本實例運行結果如下:
這個文件名的最後一個成分是:abc.cur
取得文件或文件夾的基名稱
本例演示如何使用GetBaseName方法來返回在指定的路徑中文件或者文件夾的基名稱。
代碼如下:
| <html> <body> <% Setfs=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/)) setfs=nothing %> </body> </html> |
本實例運行結果如下:
| abc cursors windows |
分享:解析ASP日期格式的數據加減計算方法在ASP中為我們提供了專門的日期加減函數。 1.日期相加DateAdd函數返回已添加指定時間間隔的日期。 DateAdd(interval,number,date) DateAdd函數的語法有以下參數(1)interval必選項。字符串表達式,表示要添加的時間間隔。有關數值,請參閱“設置”部分。