VB Script possible open multiple file locations for processing txt files?

Hi

I have a script that opens a file location but it turns out that the script needs to open mulitple file locations.

Hows the best way to do this with the exisitng code i have alread yset up?

Hes how my code to open 1 file location:

Dim sFolder
'Open location
sFolder = "C:\MyMachine\XML_Parser_\Txt"

'Check for txt files
For Each oFile In oFSO.GetFolder(sFolder).Files  
  If UCase(oFSO.GetExtensionName(oFile.Name)) = "TXT" Then
    ProcessFiles oFSO, oFile
  End if
Next

Set oFSO = Nothing

Sub ProcessFiles(FSO, File)

'Do my stuff here

Can i use my variable sFolder to specify more than one folder location?
wilko1000Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
HI,

pls try by adding your other Folders separated with a comma

Dim sFolder
 'Open location
 sFolder = "C:\MyMachine\XML_Parser_\Txt,d:\"
 For Each oFolder In Split(sFolder, ",")
 'Check for txt files
 For Each oFile In oFSO.GetFolder(oFolder).Files
   If UCase(oFSO.GetExtensionName(oFile.Name)) = "TXT" Then
     ProcessFiles oFSO, oFile
   End If
 Next oFile
 Next oFolder
 Set oFSO = Nothing

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wilko1000Author Commented:
Im used your code but  iget an error 'Path Not found'

Heres the amende code im using:

Dim sFolder
Set oFSO = CreateObject("Scripting.FileSystemObject")

sFolder = "C:\MyMachine\XML_Parser_\Txt, C:\MyMachine\XML_Parser_\Txt1"  'an existing folder on the PC

For Each oFolder In Split(sFolder, ",")
Next

For Each oFile In oFSO.GetFolder(sFolder).Files
  'bHeader = False 'tag the fact that the header for the next file is pending
  If UCase(oFSO.GetExtensionName(oFile.Name)) = "TXT" Then
    ProcessFiles oFSO, oFile
  End if
Next

Set oFSO = Nothing

Sub ProcessFiles(FSO, File)
0
wilko1000Author Commented:
Just realised is i did not set it up right, i was using sFolder when i should have used oFolder when getting the folder. Changed to correct use but now getting  error  'invalid procedure call or argument'. Heres my code based on Rgonzo1971 code:

Dim sFolder
Set oFSO = CreateObject("Scripting.FileSystemObject")

sFolder = "C:\MyMachine\XML_Parser_\Txt, C:\MyMachine\XML_Parser_\Txt1"  'an existing folder on the PC

For Each oFolder In Split(sFolder, ",")
Next

For Each oFile In oFSO.GetFolder(oFolder).Files
  'bHeader = False 'tag the fact that the header for the next file is pending
  If UCase(oFSO.GetExtensionName(oFile.Name)) = "TXT" Then
    ProcessFiles oFSO, oFile
  End if
Next

Set oFSO = Nothing

Sub ProcessFiles(FSO, File)
'Do stuff here
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

wilko1000Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for wilko1000's comment #a40673681

for the following reason:

Managed to get it to work, i placed the Next in the wrong place so was passing NULL into the folder which VB did not like. All sorted and works. Thank you
0
Rgonzo1971Commented:
Even if my answer wasn't right for you on the first time I do not see why it isn't worth awarding points
0
wilko1000Author Commented:
I thought i did except your solution?
Let me try again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.