Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello everyone,
Im using VBScript over WSH to do some file search, read, editing, and creating for an application automation.
At some point it reads a text file that says where and what to look for. It contains the folder name and what files to read in the following format:
FOLDER_NAME:FILE_X,FILE_Y;
FOLDER_NAME2:FILE_Z,FILE_W;Using the FileSystemObject, I can read the lines, but I can't do as I want.. to get the characters of the folder name before the ':' and file name character between ',' and ';' do get to the files.
Other thing I wanna know is if the VB script engine that run in APS pages is the same that execute WSH scripts.
Thankyou very much in advance!

I've been up for over 30 hours, so I probably shouldn't even be attempting this, but "restraint" and "common decency" (read: Not looking like an idiot) has never stopped me before!
Option Explicit
'oFSO - FileSystemObject to use
'sParsee - Name of file
Function ParseATextFile(oFSO, sParsee) 'As Dictionary
Set ParseATextFile = Nothing 'On function break, return Nothing
Dim dic, fParsee, line, dir, arry, key, f, i
Set dic = CreateObject("Scripting.Dictionary")
key = 1 'Note: Dictionary needs a unique key.
' We'll use an int to semi-emulate arrays.
Set fParsee = oFSO.OpenTextFile(sParsee, 1)
Do Until fParsee.AtEndOfStream
line = fParsee.ReadLine 'Step 1: Read 1 line.
line = Left(Trim(line), Len(line) - 1) 'Step 2: Get rid of traling ;
arry = Split(line, ":") 'Step 3: Split into dir/file
dir = "" 'Step 4: Build dir string
If UBound(arry) > 0 Then
For i = 0 To UBound(arry) - 1
dir = dir & arry(i) & ":"
Next 'i
dir = Left(dir, Len(dir) - 1) & "\"
'Step 5: Loop over files
For Each f In Split(arry(UBound(arry)), ",")
dic.Add key, dir & f
key = key + 1
Next 'f
End If
Loop
fParsee.Close
Set ParseATextFile = dic 'Step 6: Return
End Function
'Yeah, don't do this next part; it just tests the above.
Dim i
For Each i In ParseATextFile(CreateObject("Scripting.FileSystemObject"), _
"some.txt").Items
WScript.Echo i
Next

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |