{"id":310,"date":"2021-09-03T19:59:20","date_gmt":"2021-09-03T19:59:20","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/programming-unable-to-obtain-the-name-of-a-file-in-a-directory-28865-html"},"modified":"2021-09-03T19:59:20","modified_gmt":"2021-09-03T19:59:20","slug":"programming-unable-to-obtain-the-name-of-a-file-in-a-directory-28865-html","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/unable-to-obtain-the-name-of-a-file-in-a-directory\/28865.html","title":{"rendered":"Solved Unable To Obtain The Name Of A File In A Directory"},"content":{"rendered":"<p><td>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. <\/p>\n<p>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 &#8220;File OutPut:&#8221; 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 &#8220;Object Required&#8221; I&#8217;m not sure how to resolve it.<\/p>\n<p>I would be grateful if someone could point me in the right direction.<\/p>\n<p>Thank you<\/p>\n<p>[code]<br \/>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>Set folder = objFSO.GetFolder(strFilePath)<\/p>\n<p>for each file in folder.Files<br \/>Set objfile = objFSO.OpenTextFile(file.path, ForReading)<br \/>strContents = objfile.readAll<\/p>\n<p>&#8216;Load String Into Array<br \/>outputArray = split(strContents,&#8221;.&#8221;)<\/p>\n<p>&#8216;Check For KeyWord Match<br \/>for each strCurrentLine in outputArray<br \/>If InStr(strCurrentLine, strKeyWord) Then<\/p>\n<p>&#8216;Concatenate Matches<br \/>strOutput = strOutput &#038; &#8220;File OutPut:  &#8221; &#038; vbCRLF &#038; strCurrentLine &#038; &#8220;.&#8221; &#038; vbCRLF &#038; vbCRLF <\/p>\n<p>End if<\/p>\n<p>next <br \/>[\/code] <\/p>\n<\/p>\n<\/td>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"inline_featured_image":false,"iawp_total_views":57},"question-category":[],"question_tags":[],"class_list":["post-310","question","type-question","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=310"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=310"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}