Do While x < UBound(Drives)
'
' assumes *only* the last line does not start with [
'
if left(Drives(x),1) <> "[" then exit do
sWithoutLeft = Mid(Drives(x), 2)
nCharOfBracket = InStr (sWithoutLeft,"]")
nCharOfBracketLessOne = nCharOfBracket - 1
lUsername = Left(sWithoutLeft, nCharOfBracketLessOne)
If size >= asize Then
'You can ignore the rest of this loop, it simply reads lUsername into
another array
asize = asize + 100
ReDim Preserve sDrive(asize)
End If
sDrive(size) = lUsername
size = size+1
x = x+1
Loop
--
Michael Harris
MVP Scripting
Hi all
There is a problem I am having that hopefully someone could help me out
with. I have a script that basically reads through a text file that
contains a listing of user directories on a file server. The text file is
comprised of lines that look like the following:
[juser]
[jsmith]
[cloughli]
As you can see each username is surrounded by brackets. The problem is that
the last line of the file is not a username surrounded by brackets but
instead some information on the folder (all this info is from a batch file
that does an "ls -1" command). This last line looks like this:
4096 (595) bytes in 1 files
My question is: How do I make the code (which follows) ignore a line in the
file if it has no brackets? As of now it errors out and quits out of the
loop altogether.
Here is the code to remove the brackets and take the remaining username and
store it in a variable:
'///////////////////////
'Drives is an array that contains each line of the text file created by
doing: Drives = Split(newDrivesTextStream.ReadAll, vbNewLine)
'sWithoutLeft is a variable to hold the username without the left bracket
'nCharOfBracket determines where the next bracket is in the line of the text
file that we are looking at
'lUsername is a temporary variable to hold the left most portion of the file
line that doesn't have the remaining bracket
'\\\\\\\\\\\\\\\\\\\\\\\\\\\
Do While x < UBound(Drives)
sWithoutLeft = Mid(Drives(x), 2)
nCharOfBracket = InStr (sWithoutLeft,"]")
nCharOfBracketLessOne = nCharOfBracket - 1
lUsername = Left(sWithoutLeft, nCharOfBracketLessOne)
If size >= asize Then
'You can ignore the rest of this loop, it simply reads lUsername into
another array
asize = asize + 100
ReDim Preserve sDrive(asize)
End If
sDrive(size) = lUsername
size = size+1
x = x+1
Loop