| |
| |
| |
| Class Scan_Folder |
| |
| |
| |
| |
| Private fso, regEx, sFolderSpec, sParentFolderLayer, sMaxLayer, sFileType_RegExPatternt, sFileType, sFileList, sFolderList, sEmptyFolderList |
| Private Scan_Folder_Only, Scan_Folder_Sub |
| |
| Private Sub Class_Initialize |
| Set fso = CreateObject("Scripting.FileSystemObject") |
| Set regEx = CreateObject("VBScript.RegExp") |
| regEx.IgnoreCase = True |
| regEx.Global = True |
| regEx.MultiLine = True |
| Scan_Folder_Only = True |
| Scan_Folder_Sub = True |
| End Sub |
| |
| |
| |
| |
| Public Function FolderSpec(ByVal strFolderSpec) |
| sFolderSpec = strFolderSpec |
| End Function |
| |
| Public Function MaxLayer(ByVal strMaxLayer) |
| sMaxLayer = strMaxLayer |
| End Function |
| |
| Public Function FileType_RegExPatternt(ByVal strFileType_RegExPatternt) |
| sFileType_RegExPatternt = strFileType_RegExPatternt |
| End Function |
| |
| Public Function GetFolderList() |
| Scan_Folder_Only = True |
| Scan_Layer sFolderSpec |
| GetFolderList = sFolderList |
| End Function |
| |
| Public Function GetEmptyFolderList() |
| Scan_Folder_Only = False |
| Scan_Layer sFolderSpec |
| GetEmptyFolderList = sEmptyFolderList |
| End Function |
| |
| Public Function GetFileList() |
| Scan_Folder_Only = False |
| Scan_Layer sFolderSpec |
| GetFileList = sFileList |
| End Function |
| |
| Public Sub Close() |
| Set fso = Nothing |
| Set regEx = Nothing |
| End Sub |
| |
| |
| |
| |
| Private Function Scan_Layer(strFolderspec) |
| On Error Resume Next |
| If Not Right(strFolderspec,1) = "\" Then strFolderspec = strFolderspec & "\" |
| If Not IsEmpty(sFolderList) Then sFolderList = sFolderList & vbCrLf |
| sFolderList = sFolderList & strFolderspec |
| |
| Dim oFolder, oSubFolderItems, oSubFileItems, oSubFolder, oSubFile |
| Set oFolder = fso.GetFolder(strFolderspec) |
| |
| If Scan_Folder_Only = False Then |
| |
| Set oSubFileItems = oFolder.Files |
| |
| If oSubFileItems.Count <> 0 Then |
| For Each oSubFile In oSubFileItems |
| If IsEmpty(sFileType_RegExPatternt) Or (sFileType_RegExPatternt = "") Then |
| If Not IsEmpty(sFileList) Then sFileList = sFileList & vbCrLf |
| sFileList = sFileList & oSubFile.Path |
| Else |
| |
| regEx.Pattern = sFileType_RegExPatternt |
| If regEx.Execute( fso.GetExtensionName(oSubFile) ).Count > 0 Then |
| If Not IsEmpty(sFileList) Then sFileList = sFileList & vbCrLf |
| sFileList = sFileList & oSubFile.Path |
| End If |
| End If |
| Next |
| End If |
| End If |
| |
| Set oSubFolderItems = oFolder.SubFolders |
| |
| If oSubFolderItems.Count = 0 Then |
| |
| If Scan_Folder_Only = False Then |
| If oSubFileItems.Count = 0 Then |
| If Not IsEmpty(sEmptyFolderList) Then sEmptyFolderList = sEmptyFolderList & vbCrLf |
| sEmptyFolderList = sEmptyFolderList & strFolderspec |
| End If |
| End If |
| Else |
| |
| If Not (IsEmpty(sMaxLayer) Or (sMaxLayer = "")) Then |
| Dim s, f, n |
| s = Replace(strFolderspec, sFolderSpec, "", vbTextCompare, -1, 1) |
| f = "\" |
| n = (Len(s)-Len(Replace(s,f,"",vbTextCompare,-1,1)))/Len(f) |
| If sMaxLayer < n Then Scan_Folder_Sub = False |
| Else |
| Scan_Folder_Sub = True |
| End If |
| If Scan_Folder_Sub = True Then |
| |
| For Each oSubFolder In oSubFolderItems |
| |
| Scan_Layer oSubFolder.Path |
| Next |
| End If |
| End If |
| End Function |
| End Class |
| |
| Sub Demo(ByVal strFolderPath) |
| Dim oScanDir, sFileList, sFolderList |
| |
| Set oScanDir = New Scan_Folder |
| |
| oScanDir.FolderSpec strFolderPath |
| |
| |
| |
| oScanDir.FileType_RegExPatternt "(jpg|mp4)" |
| |
| sFileList = oScanDir.GetFileList |
| sFolderList = oScanDir.GetFolderList |
| |
| oScanDir.Close |
| |
| |
| Set fso = CreateObject("Scripting.FileSystemObject") |
| arrFilePath = Split(sFileList, vbCrLf, -1, vbTextCompare) |
| For i = 0 To UBound(arrFilePath) |
| strFilePath = arrFilePath(i) |
| WScript.Echo "所在目录: " & fso.GetFile(strFilePath).ParentFolder |
| WScript.Echo "名称: " & fso.GetFile(strFilePath).Name |
| WScript.Echo "大小: " & fso.GetFile(strFilePath).Size |
| WScript.Echo "最后修改时间: " & fso.GetFile(strFilePath).DateLastModified |
| Next |
| End SubCOPY |