0

In Excel VBA, I am trying to search C:\ folders and sub-folders for multiple keywords using WScript.Shell with DIR, FINDSTR & CLIP commands. Here is a snippet of the DOS command:

dir c:\ /s /b /ad|findstr /i "odac developer oracle" |findstr /n ^^|findstr "^[1-2]:" | CLIP

How it works:

DIR results are piped to FINDSTR which does the search of multiple keywords on the results and then again pipes to another FINDSTR which prefixes line numbers to the result. These are then regexed to another FINDSTR which ultimately reduces to only top 2 search results.

However the TOP 2 results are only from the entire results from all keywords and not from individual keywords. I do not want to resort to looping the DIR command in a VBA loop depending upon the number of keywords. The Keywords is a concatenated string of words, separated by a space.

1:c:\odac193jnj
2:c:\odac193jnj_x64

What i would like is something like this (only 2 results per keyword i.e. total 6 results):

1:c:\odac193jnj
2:c:\odac193jnj_x64
1:c:\Program Files\Oracle SQL Developer 22.2
2:c:\Program Files\Microsoft Office\root\vfs\ProgramFilesX86\Microsoft SQL Server    
1:c:\Program Files (x86)\JNJ\Oracle Data Access Components (ODAC) v19.3
2:c:\Program Files (x86)\JNJ\Oracle Data Access Components (ODAC) x64 v19.3


I also do not want the 1:, 2: to be displayed or prefixed in the string.

Any help would be most appreciated.

sifar
  • 1,086
  • 1
  • 17
  • 43

0 Answers0