• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 59
  • Last Modified:

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?
0
wilko1000
Asked:
wilko1000
  • 4
  • 2
1 Solution
 
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now