Computing.Net > Forums > Programming > WSH VBScript String Manipulation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

WSH VBScript String Manipulation

Reply to Message Icon

Name: noodles
Date: September 25, 2008 at 06:33:52 Pacific
OS: Win 2000 Server
CPU/Ram: 2x P3 1.33 / 2GB
Product: Dell
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: September 25, 2008 at 20:04:55 Pacific
Reply:

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


0

Response Number 2
Name: noodles
Date: September 26, 2008 at 07:46:54 Pacific
Reply:

Thank you very much Razor!
Will help me a lot :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: WSH VBScript String Manipulation

VB String Manipulation www.computing.net/answers/programming/vb-string-manipulation/3883.html

Functions & String Manipulation www.computing.net/answers/programming/functions-string-manipulation/17352.html

String Manipulation www.computing.net/answers/programming/string-manipulation/9519.html