日期:2008-07-14  浏览次数:20954 次

Aiyiweb.Com提示:指定的文件存在吗?本例演示如何首先创建FileSystemObject对象,然后使用FileExists方法来探测某文件能否存在。指定的文件夹存在吗?本例演示如何使用FolderExists方法探测某文件夹能否存在。指定的驱动器存在吗?本例演示如何使用DriveExists方法来探测某个驱动器能否

FileSystemObject 对象

指定的文件存在吗?

本例演示如何首先创建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>

本实例运转结果如下:

 文件 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>

本实例运转结果如下:

 文件夹 c:\temp 不存在。

指定的驱动器存在吗?

本例演示如何使用DriveExists方法来探测某个驱动器能否存在。

本文由爱易网任务室(www.Aiyiweb.Com)发布!转载和采集的话请不要去掉!谢谢。
 
本示例代码如下:

<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.driveexists("c:") = true then
      Response.Write("驱动器 c: 存在。")
Else
      Response.Write("驱动器 c: 不存在。")
End If
Response.write("<br>")
if fs.driveexists("g:") = true then
      Response.Write("驱动器 g: 存在。")
Else
      Response.Write("驱动器 g: 不存在。")
End If
set fs=nothing
%>
</body>
</html>

本实例运转结果如下:

 驱动器 c: 存在。
驱动器 g: 存在。

取得某个指定驱动器的名称

本例演示如何使用GetDriveName方法来取得某个指定的驱动器的名称。

本示例代码如下:

<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetDriveName("c:\windows\cursors\abc.cur")
Response.Write("驱动器名称是:" & p)
set fs=nothing
%>
</body>
</html>

本实例运转结果如下:

 驱动器名称是:c:

取得某个指定路径的父文件夹的名称

本例演示如何使用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>

本实例运转结果如下:

c:\windows\cursors\abc.cur 的父文件夹名称是:c:\winnt\cursors

取得文件夹扩展名

本例演示如何使用GetExtensionName方法来取得指定的路径中的最后一个成分的文件扩展名。

看到本信息说明该文是通过爱易网(www.Aiyiweb.Com)整理发布的,请不要删掉!

本示例代码如下:

 <html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Response.Write("文件 3dgarro 的文件扩展名是:")
Response.Write(fs.GetExtensionName("