私は vbscripting を初めて使用し、これらのファイルを別のディレクトリに移動できるように、ファイル名に一致する文字列を含む 6 つのファイルを見つける必要があるというタスクを受け取りました。ファイル名内のすべての文字列を見つけるために、正規表現パターン「\d{8}-\d{6}」を使用しています。
ディレクトリで検索を行い、ファイル名に一致する文字列を持つ6つのファイルがあるかどうかを確認して、それらを配列に保存してからファイルを別のディレクトリに移動できるようにするにはどうすればよいですか?
これまでに書いたスクリプト:
Set objFS = CreateObject("Scripting.FileSystemObject")
strShareDirectory = "in\"
strDumpStorageDir = "out\"
Set objFolder = objFS.GetFolder(strShareDirectory)
Set colFiles = objFolder.Files
Set re = New RegExp
re.Global = True
re.IgnoreCase = False
re.Pattern = "-\d{8}-\d{6}"
Dim curFile, matchValue
Dim i: i = 0
For Each objFile in colFiles
bMatch = re.Test(objFile.Name)
curFile = objFile.Name
If bMatch Then
ReDim preserve matches(i)
Matches(i) = curFile
i = (i + 1)
For Each objFile1 in colFiles
If objFile1.Name <> objFile.Name Then
For each match in re.Execute(objFile1.Name)
matchValue = match.Value
Exit For
Next
If (Instr(curFile, matchValue) > 0) Then
matchCount = 1
For Each match1 in re.Execute(objFile1.Name)
curFile1 = objFile1.Name
matchValue1 = match1.Value
Exit For
'If Then
Next
'msgbox(curFile1)
End If
End If
Next
End If
Next
これが、私が使用しているサンプル ディレクトリの外観です。