1

我在编写 VBScript 方面很糟糕,对于任何有编写 VBScript 代码经验的人来说,我有一个问题应该很简单。我有一个脚本文件,它从指定目录开始解析文件系统,然后对每个子文件夹进行递归搜索。然后将文件名、路径名和修改日期发送到将数据写入表的 SQL 存储过程。这按描述工作,但我需要在脚本中放置一个过滤器,告诉脚本忽略任何以 PDF_IMAGES\ 或 TIF_IMAGES 结尾的路径。我不想处理这些文件夹或这些文件夹中的任何子文件夹中的任何内容。这是我到目前为止的片段:

Const startDir = "\\myfileshare\images"

'Variables
Dim objFSO, strFolder, subFolder

'Use the FileSystemObject to search directories and create the text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Call the Search subroutine to start the recursive search.
Search objFSO.GetFolder(startDir)

Sub Search(sPath)

    'Assign the value of sPath to the strFolder variable.
    strFolder = sPath

    'Use undeclared variable to run function
    strReturnFileNames = FindLatestFileMatchingRegex(strFolder & "\", "*.*" ) 

    strFolder = ""

    'Find EACH SUBFOLDER.
    For Each subFolder In sPath.SubFolders
        'Call the Search subroutine to start the recursive search on EACH SUBFOLDER.
        Search objFSO.GetFolder(subFolder.Path)
    Next
End Sub

任何帮助,将不胜感激。

4

1 回答 1

1
Right(subFolder.Path, 7)

将为您提供路径的最后六个字符。然后您需要将它们与_IMAGES 进行比较。您可以为此使用 StrComp

StrComp("_IMAGES", path)

如果它们相同,那将为您提供 0。所以像这样(未经测试)的东西会给你这个想法。

If Not StrComp("_IMAGES", Right(subFolder.Path, 7)) = 0 then
Search objFSO.GetFolder(subFolder.Path)
End If

这是填补空白的有用参考。

我一点也不怀念 vbscript

于 2013-05-15T22:03:54.373 回答