需要知道如何跳过VBScript中的子文件夹

时间:2013-05-15 21:01:41

标签: vbscript windows-scripting

我写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

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分: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

这是填补空白的helpful reference

我根本不会错过vbscript