0

如果有以下 VBScript 用于递归查找一组文件夹中的所有文件。我只是在网上的某个地方找到了这个,不能因此而受到赞扬。

fileExtension = ".jpg"
folderPath = "C:\Pictures"
computerName = "."
arrFIL = Array()

If Right(folderPath,1) = "\" Then folderPath = Left(folderPath,Len(folderPath)-1)

Set wmiObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computerName & "\root\cimv2")
Set folderObject = wmiObject.Get("Win32_Directory='" & folderPath & "'")

EnumFolders folderObject, wmiObject, arrFIL
strFIL = UBound(arrFIL) + 1 & " files found with extension '" & fileExtension & "':" & vbCrLf & vbCrLf

For intFIL = 0 To UBound(arrFIL)
    Set objFile = objFSO.GetFile(arrFIL(intFIL))
    strFIL = strFIL & arrFIL(intFIL) & vbCrLf
Next
WScript.Echo strFIL

Sub EnumFolders(folderObject, wmiObject, arrFIL)
    On Error Resume Next
    Dim objSD1
    Dim objSD2
    Dim objFI1
    Dim objFI2
    Set objSD1 = wmiObject.ExecQuery("Associators of {Win32_Directory.Name='" & fold    erObject.Name & "'} Where AssocClass=Win32_SubDirectory ResultRole=PartComponent")

    For Each objSD2 in objSD1
        EnumFolders objSD2, wmiObject, arrFIL
    Next    
    On Error Goto 0

    Set objFI1 = wmiObject.ExecQuery("Associators of {Win32_Directory.Name='" & folderObject.Name & "'} Where ResultClass=CIM_DataFile")
    For Each objFI2 in objFI1
    If Right(objFI2.Name,Len(fileExtension)) = fileExtension Then
        intFIL = UBound(arrFIL) + 1
            ReDim Preserve arrFIL(intFIL)
            arrFIL(intFIL) = objFI2.Name
        End If
    Next
End Sub

我需要做的是针对 C:\Pictures 中的一堆文件夹运行此操作,并让它返回照片的拍摄日期属性为每月 23 日的所有文件。这可能吗?我将如何实现这一目标?

谢谢

4

1 回答 1

1

我会使用Shell.Application对象而不是 WMI:

Const Name      =  0
Const DateTaken = 12

folderPath = "C:\Pictures"

Set re = New RegExp
re.Pattern = "[^0-9:./ ]"
re.Global  = True

Traverse CreateObject("Shell.Application").Namespace(folderPath)

Sub Traverse(fldr)
  For Each obj In fldr.Items
    If obj.IsFolder Then
      Traverse obj.GetFolder
    ElseIf LCase(obj.Type) = "jpeg image" Then
      If Day(re.Replace(fldr.GetDetailsOf(obj, DateTaken), "")) = 23 Then
        WScript.Echo fldr.GetDetailsOf(obj, Name)
      End If
    End If
  Next
End Sub
于 2013-03-27T22:57:39.187 回答