Domanda

I am horrible at writing VBScript and I have a question that should be pretty simple for anyone who has any experience writing VBScript code. I have a script file that parses the file system starting at a specified directory, then doing a recursive search through each subfolder. The file names, path name, and date modified are then sent to an SQL stored procedure that writes the data to a table. This is working as described but I need to put a filter on in script to tell the script to ignore any paths ending in PDF_IMAGES\ or TIF_IMAGES. I don't want to process anything in those folders or any subfolders within those folders. Here is the snippet of what I have so far:

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

Any help would be appreciated.

È stato utile?

Soluzione

Right(subFolder.Path, 7)

will give you the last six characters of the path. You then need to compare them to _IMAGES. You can use StrComp for that

StrComp("_IMAGES", path)

That will give you 0 if they are identical. So something like this (untested) will give you the idea.

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

Here's a helpful reference to fill in the gaps.

I don't miss vbscript at all

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top