使用 VB 脚本在文件夹名称中查找单词

Look for a word within the folder name with VB scripting

如何使用 vb 脚本读取文件夹名称并查找特定单词?

EG:

文件夹名称= 1234abc_Complete 我如何获得完整的文本并将其存储为变量?

谢谢!

下面的代码应该可以满足您的要求。

Option Explicit
' create a FileSystemObject
Dim oFso : Set oFso = CreateObject("Scripting.FileSystemObject")
' Set a reference to the folder which contains the folders you want to look through
Dim oFolder : Set oFolder = oFso.GetFolder("PathToFolderInHere")
Dim oSubFolder, myVar
' loop through each subfolder
For Each oSubFolder in oFolder.SubFolders
    ' If the oSubFolder contains the word complete then set myVar and exit the loop
    If InStr(1, oSubFolder.Name, "complete", vbTextCompare) > 0 Then
        myVar = oSubFolder.Name
        Exit For
    End If
Next

' do whatever with myVar (the folder name you wanted in the variable).