Solved Unable to obtain name of file in directory

Having become unstuck with a script I am working on I would appreciate some help. Basically, it reads in the string content of each file in a directory into an array (period delimited). It then searches for a keyword and if found concatenates each sentence in which it is found. The echoed output shows what was found in each file.

This works perfectly well and does what I want but in the 3rd last line of the piece of code shown below where I have "File OutPut:" I would like to have the actual name of the file instead. I have tried every which way to achieve this but without success. Although I think it is to do with "Object Required" I'm not sure how to resolve it.

I would be grateful if someone could point me in the right direction.
Thank you

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder(strFilePath)
 
for each file in folder.Files
Set objfile = objFSO.OpenTextFile(file.path, ForReading)
strContents = objfile.readAll

'Load String Into Array
outputArray = split(strContents,".")

'Check For KeyWord Match
for each strCurrentLine in outputArray
If InStr(strCurrentLine, strKeyWord) Then
  
'Concatenate Matches
strOutput = strOutput & "File OutPut:  " & vbCRLF & strCurrentLine & "." & vbCRLF & vbCRLF 

End if

next
 

My Computer

Is that Visual Basic? Just assign the file name to the variable when you open the file, or are you not able to find the file name?
 

My Computer

System One

  • Manufacturer/Model
    HP Compaq Presario C700
    CPU
    Intel Pentium Dual Core T2370
    Motherboard
    HP 30D9
    Memory
    2GB 677Mhz
    Graphics Card(s)
    Mobile Intel 965 Express Chipset Family
    Sound Card
    Conexant High Definition SmartAudio 221
    Screen Resolution
    1280 x 800
    Hard Drives
    WDC WD1200BEVS-60UST0
Hi, XGenius, this is Visual Basic Script a simpler version of Visual Basic. Unfortunately as multiple files were read in from the directory there was no way I could tell in which file a match was made. That was why I was trying to find out how to do it.

However, it is now resolved using File.Name. Although I tried that before it threw up an error but I have worked out that the error was actually attributable a scrap of code I inserted earlier in the script while trying to find get the answer. Unfortunately, I omitted to remove this scrap of code with the result that it threw up the error. As this occurred earlier in the script the error was thrown up before the coded section with file.name was reached. I just jumped to the conclusion that it was incorrect.



Any thank you for taking the time to reply!
 

My Computer

No problem, I'm a programming enthusiast myself!
 

My Computer

System One

  • Manufacturer/Model
    HP Compaq Presario C700
    CPU
    Intel Pentium Dual Core T2370
    Motherboard
    HP 30D9
    Memory
    2GB 677Mhz
    Graphics Card(s)
    Mobile Intel 965 Express Chipset Family
    Sound Card
    Conexant High Definition SmartAudio 221
    Screen Resolution
    1280 x 800
    Hard Drives
    WDC WD1200BEVS-60UST0
Back
Top