Note that there are some explanatory texts on larger screens.

plurals
  1. POvbscript, find matches in filenames
    primarykey
    data
    text
    <p>I'm new to vbscripting and I just received a task that requires me to find 6 files with matching strings in the filename so that I can move these files to a different directory. I am using the regex pattern "\d{8}-\d{6}" to locate all of the strings within the filenames.</p> <p>How would I go about in doing a search in a directory and checking to see if there are 6 files with matching strings in their filenames so that I can store them into an array and then move the files to another directory?</p> <p>The script I have written so far:</p> <pre><code>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 &lt;&gt; objFile.Name Then For each match in re.Execute(objFile1.Name) matchValue = match.Value Exit For Next If (Instr(curFile, matchValue) &gt; 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 </code></pre> <p>Here is what my sample directory that I am working with looks like. <img src="https://i.stack.imgur.com/N4Hbd.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload