Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read text from file then create a directory from that

Status
Not open for further replies.

moogeboo

MIS
Aug 7, 2003
28
US
Hello all,

I have a text file that basically contains one line that reads, as an example:

adduser -u jsmith -n "xxxxxxxxx"

now, what i'd like to do is to be able to make a directory name called jsmith, or whatever username that the text file will contain (as designated after the -u), and create a directory in that name. The username length will vary, but the -n will always appear after the username, and the -u will always appear before the username.

Thanks in advance,
 
You can play with the InStr and Mid functions to locate the username, and with the CreateFolder method of the FileSystemObject object.

Hope This Help
PH.
 
Once you have it in a variable, you can do something simple like this, then use the filesystemobject to create the folder. I had to add the extra quotes to directly assign it.

Info="""adduser -u jsmith -n ""xxxxxxxxx"""
Array1= Split(info," ")
msgbox Array1(2)
 
This isn't as elegant as what MisterNiceGuy is suggesting, but it is a complete solution that will read from your existing text file. Just change the path to the file in the script.

'==========================================================================
'
' NAME: findusername.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 2/9/2004
'
' COMMENT: <comment>
'
'==========================================================================
On Error Resume Next
'open the file system object
'open the data file
dim oFSO, strText, readfile
set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
set readfile = oFSO.OpenTextFile(&quot;c:\test.txt&quot;, 1, false)
strText = readfile.ReadAll
readfile.close

For x = 1 To Len(strText)

If Mid(strText,x,2) = &quot;-u&quot; Then
startPosition = x + 3
'MsgBox &quot;Found it at position &quot; & x
Else x = x + 1
End If

Next

For x = 1 To Len(strText)

If Mid(strText,x,2) = &quot;-n&quot; Then
endPosition = x - 1
endPosition = endPosition - startPosition
'MsgBox &quot;Found it at position &quot; & x
Else x = x + 1
End If

Next

UserName = Mid(strText,startPosition,endPosition)
MsgBox Username
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top