0

I am trying to loop through all the files in a folder and get the path of one that contains a specific part of text. The text is not always in the same position and the folder is a network folder. What would be the fastest way to do this in a network folder that contains hundreds of files with more than 30Mb each?

The Dir() solution did not work as it says "Bad file name or number" (Error 52). I am referencing the network path as \\thisisthefolder\anotherfolder\

Community
  • 1
  • 1
peetman
  • 669
  • 2
  • 15
  • 30
  • 1
    Possible duplicate of [Loop through files in a folder using VBA?](http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba) – Stupid_Intern Jun 29 '16 at 14:17
  • 1
    File size doesn't matter if you just want to find the file in the folder. – Stupid_Intern Jun 29 '16 at 14:18
  • Is the text in question part of the file name or is it something that occurs in the file itself? If the latter, are these files text files? xlsx files? Also -- I am adding a VBScript tag to your question since I suspect that the optimal answer involves File System Objects, and any VBScript solution is easily run from VBA. – John Coleman Jun 29 '16 at 14:35
  • The `Dir()` solution did not work as it says "Bad file name or number" (Error 52). I am referencing the network path as `\\thisisthefolder\anotherfolder` – peetman Jun 29 '16 at 14:37
  • 1
    Just add \ to the end of the folder string so it should be \thisisthefolder\anotherfolder\ – Stupid_Intern Jun 29 '16 at 14:40
  • 1
    I got it! I had to add \ by the end of the string – peetman Jun 29 '16 at 14:41

0 Answers0