📄 directoryinfo.cls
字号:
p = Path.GetDirectoryName(mPath)
If Len(p) > 0 Then Set Parent = Cor.NewDirectoryInfo(p)
End Property
''
' Returns a DirectoryInfo object of the root directory of this instance.
'
' @return A DirectoryInfo object of the root.
'
Public Property Get Root() As DirectoryInfo
Set Root = Cor.NewDirectoryInfo(Path.GetPathRoot(mPath))
End Property
''
' Creates the path represented by this instance.
'
Public Sub Create()
Call Directory.CreateDirectory(mPath)
End Sub
''
' Creates a directory within this instance, returning the new subdirectory.
'
' @param sPath The new subdirectory to be created.
' @return A DirectoryInfo object of the new subdirectory path.
'
Public Function CreateSubdirectory(ByVal sPath As String) As DirectoryInfo
Set CreateSubdirectory = Directory.CreateDirectory(Path.Combine(mPath, sPath))
End Function
''
' Deletes this directory if it is empty, or all of its contents and itself
' if Recursive is set to True.
'
' @param Recursive Indicates if all entries in the directory should be deleted.
'
Public Sub Delete(Optional ByVal Recursive As Boolean)
Call Directory.Delete(mPath, Recursive)
End Sub
''
' Returns a list of directories within this directory.
'
' @param SearchPattern A pattern for all directories to match.
' @return A list of all matching directories.
' @remarks If no matching directories were found, then an empty array is returned.
'
Public Function GetDirectories(Optional ByVal SearchPattern As String = "*") As DirectoryInfo()
Dim Ret() As DirectoryInfo
Dim Paths() As String
Paths = Directory.GetDirectories(mPath, SearchPattern)
Dim NumPaths As Long
NumPaths = cArray.GetLength(Paths)
If NumPaths > 0 Then
Dim i As Long
ReDim Ret(0 To NumPaths - 1)
For i = 0 To NumPaths - 1
Set Ret(i) = Cor.NewDirectoryInfo(Path.Combine(mPath, Paths(i)))
Next i
Else
' No subdirectories were found.
' LAME SPEC: .NET actually returns a zero-length array, where the
' MSDN says it returns the root directory.
Ret = cArray.CreateInstance(ciObject)
End If
GetDirectories = Ret
End Function
''
' Moves this directory and its contents to the specified path.
'
' @param DestDirName The new path and name of the directory.
'
Public Sub MoveTo(ByVal DestDirName As String)
Call Directory.Move(mPath, DestDirName)
mPath = Path.GetFullPath(DestDirName)
mOriginalPath = Path.GetDirectoryName(mPath)
End Sub
''
' Returns a list of file matching the pattern in this directory.
'
' @param SearchPattern The pattern the files must match.
' @return A list of files that matched the pattern.
' @remarks If no files matched the pattern, a zero-length array is returned.
'
Public Function GetFiles(Optional ByVal SearchPattern As String = "*") As FileInfo()
Dim Ret() As FileInfo
Dim Files() As String
Files = Directory.GetFiles(mPath, SearchPattern)
Dim NumFiles As Long
NumFiles = cArray.GetLength(Files)
If NumFiles > 0 Then
Dim i As Long
ReDim Ret(0 To NumFiles - 1)
For i = 0 To NumFiles - 1
Set Ret(i) = Cor.NewFileInfo(Path.Combine(mPath, Files(i)))
Next i
Else
Ret = cArray.CreateInstance(ciObject)
End If
GetFiles = Ret
End Function
''
' Returns a list of all entries in the directory that match the pattern.
'
' @param SearchPattern The pattern to match against all entries.
' @return A list of all entries that matched the pattern.
' @remarks If no entries matched the pattern, a zero-length array is returned.
'
Public Function GetFileSystemInfos(Optional ByVal SearchPattern As String = "*") As FileSystemInfo()
Dim Files() As String
Files = Directory.GetFiles(mPath, SearchPattern)
Dim Folders() As String
Folders = Directory.GetDirectories(mPath, SearchPattern)
Dim InfoCount As Long
InfoCount = cArray.GetLength(Files) + cArray.GetLength(Folders)
Dim Ret() As FileSystemInfo
If InfoCount > 0 Then
Dim i As Long
ReDim Ret(0 To InfoCount - 1)
For i = 0 To UBound(Files)
Set Ret(i) = Cor.NewFileInfo(Path.Combine(mPath, Files(i)))
Next i
Dim j As Long
j = UBound(Files) + 1
For i = 0 To UBound(Folders)
Set Ret(j + i) = Cor.NewDirectoryInfo(Path.Combine(mPath, Folders(i)))
Next i
Else
' None found, so return an empty array.
Ret = cArray.CreateInstance(ciObject)
End If
GetFileSystemInfos = Ret
End Function
''
' Returns a string representation of this object instance.
'
' @return String representing this instance.
Public Function ToString() As String
ToString = mOriginalPath
End Function
''
' Returns a boolean indicating if the value and this object
' instance are the same instance.
'
' @param value The value to compare equality to.
' @return Boolean indicating equality.
Public Function Equals(ByRef Value As Variant) As Boolean
Equals = Object.Equals(Me, Value)
End Function
''
' Returns a pseudo-unique number identifying this instance.
'
' @return Pseudo-unique number identifying this instance.
Public Function GetHashCode() As Long
GetHashCode = ObjPtr(CUnk(Me))
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Friend Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Friend Sub Init(ByVal sPath As String)
Call Path.VerifyPath(sPath)
mOriginalPath = sPath
If Not Path.IsPathRooted(sPath) Then
mPath = Path.GetFullPath(sPath)
Else
mPath = sPath
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Private Helpers
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub MarkDirty()
mIsDirty = True
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Class_Initialize()
Call MarkDirty
End Sub
Private Sub Class_ReadProperties(PropBag As PropertyBag)
Call Init(PropBag.ReadProperty("Path"))
End Sub
Private Sub Class_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Path", mOriginalPath)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IObject Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_Equals(Value As Variant) As Boolean
IObject_Equals = Equals(Value)
End Function
Private Function IObject_GetHashcode() As Long
IObject_GetHashcode = GetHashCode
End Function
Private Function IObject_ToString() As String
IObject_ToString = ToString
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FileSystemInfo Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Property Get FileSystemInfo_Attributes() As FileAttributes
FileSystemInfo_Attributes = Attributes
End Property
Private Property Let FileSystemInfo_Attributes(ByVal RHS As FileAttributes)
Attributes = RHS
End Property
Private Property Set FileSystemInfo_CreationTime(ByVal RHS As Variant)
Set CreationTime = RHS
End Property
Private Property Let FileSystemInfo_CreationTime(ByVal RHS As Variant)
CreationTime = RHS
End Property
Private Property Get FileSystemInfo_CreationTime() As Variant
Set FileSystemInfo_CreationTime = CreationTime
End Property
Private Property Set FileSystemInfo_CreationTimeUtc(ByVal RHS As Variant)
Set CreationTimeUtc = RHS
End Property
Private Property Let FileSystemInfo_CreationTimeUtc(ByVal RHS As Variant)
CreationTimeUtc = RHS
End Property
Private Property Get FileSystemInfo_CreationTimeUtc() As Variant
Set FileSystemInfo_CreationTimeUtc = CreationTimeUtc
End Property
Private Sub FileSystemInfo_Delete()
Call Delete
End Sub
Private Function FileSystemInfo_Equals(Value As Variant) As Boolean
FileSystemInfo_Equals = Equals(Value)
End Function
Private Property Get FileSystemInfo_Exists() As Boolean
FileSystemInfo_Exists = Exists
End Property
Private Property Get FileSystemInfo_Extension() As String
FileSystemInfo_Extension = Extension
End Property
Private Property Get FileSystemInfo_FullName() As String
FileSystemInfo_FullName = FullName
End Property
Private Function FileSystemInfo_GetHashCode() As Long
FileSystemInfo_GetHashCode = GetHashCode
End Function
Private Property Set FileSystemInfo_LastAccessTime(ByVal RHS As Variant)
Set LastAccessTime = RHS
End Property
Private Property Get FileSystemInfo_LastAccessTime() As Variant
Set FileSystemInfo_LastAccessTime = LastAccessTime
End Property
Private Property Let FileSystemInfo_LastAccessTime(ByVal RHS As Variant)
LastAccessTime = RHS
End Property
Private Property Set FileSystemInfo_LastAccessTimeUtc(ByVal RHS As Variant)
Set LastAccessTimeUtc = RHS
End Property
Private Property Let FileSystemInfo_LastAccessTimeUtc(ByVal RHS As Variant)
LastAccessTimeUtc = RHS
End Property
Private Property Get FileSystemInfo_LastAccessTimeUtc() As Variant
Set FileSystemInfo_LastAccessTimeUtc = LastAccessTimeUtc
End Property
Private Property Set FileSystemInfo_LastWriteTime(ByVal RHS As Variant)
Set LastWriteTime = RHS
End Property
Private Property Let FileSystemInfo_LastWriteTime(ByVal RHS As Variant)
LastWriteTime = RHS
End Property
Private Property Get FileSystemInfo_LastWriteTime() As Variant
Set FileSystemInfo_LastWriteTime = LastWriteTime
End Property
Private Property Set FileSystemInfo_LastWriteTimeUtc(ByVal RHS As Variant)
Set LastWriteTimeUtc = RHS
End Property
Private Property Let FileSystemInfo_LastWriteTimeUtc(ByVal RHS As Variant)
LastWriteTimeUtc = RHS
End Property
Private Property Get FileSystemInfo_LastWriteTimeUtc() As Variant
Set FileSystemInfo_LastWriteTimeUtc = LastWriteTimeUtc
End Property
Private Property Get FileSystemInfo_Name() As String
FileSystemInfo_Name = Name
End Property
Private Sub FileSystemInfo_Refresh()
Call Refresh
End Sub
Private Function FileSystemInfo_ToString() As String
FileSystemInfo_ToString = ToString
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -