VB基础:认识VB的文件系统对象FSO |
出处:CSDN |
[04-3-16 15:14] | 作者:zhangking |
要应用 FSO 对象,须要引用一个名为 Scripting 的类型库,方法是,执行 VB6.0 的菜单项“工程/引用”,添加引用列表框中的“Microsoft Scripting Runtime”一项。然后我们在“对象浏览器”中就可以看到 Scripting 类型库下的众多对象及其方法、属性。
1、判断光驱的盘符:
Function GetCDROM() ' 返回光驱的盘符(字母)
Dim Fso As New FileSystemObject '创建 FSO 对象的一个实例
Dim FsoDrive As Drive, FsoDrives As Drives '定义驱动器、驱动器集合对象
Set FsoDrives = Fso.Drives
For Each FsoDrive In FsoDrives '遍历所有可用的驱动器
If FsoDrive.DriveType = CDRom Then '如果驱动器的类型为 CDrom
GetCDROM = FsoDrive.DriveLetter '输出其盘符
Else
GetCDROM = ""
End If
Next
Set Fso = Nothing
Set FsoDrive = Nothing
Set FsoDrives = Nothing
End Function
2、判断文件、文件夹是否存在:
'返回布尔值:True 存在,False 不存在,filername 文件名
Function FileExist(filename As String)
Dim Fso As New FileSystemObject
If Fso.FileExists(filename) = True Then
FileExist = True
Else
FileExist = False
End If
Set Fso = Nothing
评论