FileSystemObject 對(duì)象
指定的文件存在嗎?
本例演示如何首先創(chuàng)建FileSystemObject對(duì)象,然后使用FileExists方法來(lái)探測(cè)某文件是否存在。
本示例代碼如下:
以下為引用的內(nèi)容:
<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方法探測(cè)某文件夾是否存在。
本示例代碼如下:
以下為引用的內(nèi)容:
<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 不存在。
指定的驅(qū)動(dòng)器存在嗎?
本例演示如何使用DriveExists方法來(lái)探測(cè)某個(gè)驅(qū)動(dòng)器是否存在。
本示例代碼如下:
以下為引用的內(nèi)容:
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.driveexists("c:") = true then
Response.Write("驅(qū)動(dòng)器 c: 存在。")
Else
Response.Write("驅(qū)動(dòng)器 c: 不存在。")
End If
Response.write("<br>")
if fs.driveexists("g:") = true then
Response.Write("驅(qū)動(dòng)器 g: 存在。")
Else
Response.Write("驅(qū)動(dòng)器 g: 不存在。")
End If
set fs=nothing
%>
</body>
</html>
|
本實(shí)例運(yùn)行結(jié)果如下:
驅(qū)動(dòng)器 c: 存在。
驅(qū)動(dòng)器 g: 存在。
取得某個(gè)指定驅(qū)動(dòng)器的名稱(chēng)
本例演示如何使用GetDriveName方法來(lái)取得某個(gè)指定的驅(qū)動(dòng)器的名稱(chēng)。
本示例代碼如下:
以下為引用的內(nèi)容:
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetDriveName("c:\windows\cursors\abc.cur")
Response.Write("驅(qū)動(dòng)器名稱(chēng)是:" & p)
set fs=nothing
%>
</body>
</html>
|
本實(shí)例運(yùn)行結(jié)果如下:
驅(qū)動(dòng)器名稱(chēng)是:c:
取得某個(gè)指定路徑的父文件夾的名稱(chēng)
本例演示如何使用GetParentFolderName方法來(lái)取得某個(gè)指定的路徑的父文件夾的名稱(chēng)。
本示例代碼如下:
以下為引用的內(nèi)容:
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur")
Response.Write("c:\windows\cursors\abc.cur 的父文件夾名稱(chēng)是:" & p)
set fs=nothing
%>
</body>
</html>
|
本實(shí)例運(yùn)行結(jié)果如下:
c:\windows\cursors\abc.cur 的父文件夾名稱(chēng)是:c:\winnt\cursors
取得文件夾擴(kuò)展名
本例演示如何使用GetExtensionName方法來(lái)取得指定的路徑中的最后一個(gè)成分的文件擴(kuò)展名。
本示例代碼如下:
以下為引用的內(nèi)容:
<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方法來(lái)取得指定的路徑中的最后一個(gè)成分的文件名。