SAPIEN Forums

Search a string in a text file. If it does not exist add it to the file.

Search a string in a text file. If it does not exist add it to the file.

Posted: Thu Sep 27, 2012 5:51 am

by kocchB

I have a group of ini files that call procedures. The ini file name is based on the user logon ID.
For example: UserID1.ini UserID2.ini UserID3.ini .....
The path of the ini files is c:ini files
I also have a text file named usernames.txt populated with user logon ID(s). The content of usernames.txt looks like:
UserID1
UserID2
UserID3
UserID4
........

Need a Vbscript that will read (c:tempusernames.txt).
For each userID in usernames.txt, verify if there an ini file with the same name exist.
If true, search the existing file for the string "Net Use * ServerNameShareName"
If string exist do nothing
Else write the string "Net Use * ServerNameShareName" to the file.
If the ini file does not exist. Create one and write the string in it.

The script is below. When you run the script. it write several line of the string Net Use * ServerNameShareName on existing ini files that did not have it.

For example User1ID.ini content before is ( Net User Q ServerXshareX )
When you run the script, depending on how many username (5 for example) you have in usernames.txt