文件系统对象(File System Object)函数系列之一

Public Function GetExeVersion(ByVal sFullName As String) As String ‘获取可执行文件版本号
Dim FSO As Object
GetExeVersion = “”
If Not FileExist(sFullName) Then Exit Function
Set FSO = CreateObject(“Scripting.FileSystemObject”)
GetExeVersion = FSO.GetFileVersion(sFullName)
Set FSO = Nothing
End Function

Public Function GetExeInfo(ByVal sFullName As String) As String ‘获取可执行文件的信息
Dim FSO As Object
GetExeInfo = “”
If Not FileExist(sFullName) Then Exit Function
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Dim oFile As Object
Set oFile = FSO.GetFile(sFullName)
GetExeInfo = oFile.Size ‘Type/Attributes/Name/Path .etc
Set FSO = Nothing
End Function

Public Function GetWindows() As String ‘获取 Windows
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
GetWindows = FSO.GetSpecialFolder(0)
Set FSO = Nothing
End Function

Public Function GetSystem() As String ‘获取 System
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
GetSystem = FSO.GetSpecialFolder(1)
Set FSO = Nothing
End Function

Public Function GetTemporary() As String ‘获取 Temporary
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
GetTemporary = FSO.GetSpecialFolder(2)
Set FSO = Nothing
End Function

Public Function GetFileList(ByVal sFolder As String) As String ‘获取文件夹本级内所有文件
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Dim oFolder As Object, oItem As Object, oCollection As Object
Dim sList As String
If FSO.FolderExists(sFolder) Then
Set oFolder = FSO.GetFolder(sFolder)
Set oCollection = oFolder.Files
‘Debug.Print oCollection.Count
For Each oItem In oCollection
sList = sList & oItem.Name
sList = sList & “|”
Next
GetFileList = sList
Else
GetFileList = “”
End If
Set FSO = Nothing
End Function

Public Function GetFolderList(ByVal sFolder As String) As String ‘获取文件夹下一级所有子文件夹
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Dim oFolder As Object, oItem As Object, oCollection As Object
Dim sList As String
If FSO.FolderExists(sFolder) Then
Set oFolder = FSO.GetFolder(sFolder)
Set oCollection = oFolder.SubFolders
‘Debug.Print oCollection.Count
For Each oItem In oCollection
sList = sList & oItem.Name
sList = sList & “|”
Next
GetFolderList = sList
Else
GetFolderList = “”
End If
Set FSO = Nothing
End Function

Public Function GetDrivesList() As String
Dim FSO As Object
Set FSO = CreateObject(“Scripting.FileSystemObject”)
Dim oItem As Object, oCollection As Object
Dim sList As String
Set oCollection = FSO.Drives
For Each oItem In oCollection
‘Debug.Print oItem.SerialNumber
sList = sList & oItem.DriveLetter
sList = sList & “|”
Next
GetDrivesList = sList
Set FSO = Nothing
End Function

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注