So I created these two arrays Approved shares and current shares.
'Reads Approvedshare txt and makes the txt file into an array
public objFSO
set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objTextFile
Set objTextFile = objFSO.OpenTextFile ("C:\Users\a352592\Desktop\Abdullahi\Remove Shares Utility\approvedshares.txt")
Public strTextFile, strData, arrLines, LineCount
CONST ForReading = 1
strTextFile = ("C:\Users\a352592\Desktop\Abdullahi\Remove Shares Utility\approvedshares.txt")
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)
LineCount = UBound(arrLines) + 1
wscript.echo "Approved share count : " &Linecount
'Reads current shares txt and also makes that txt into an array
Set objTextFile1 = objFSO.OpenTextFile ("C:\Users\a352592\Desktop\Abdullahi\Remove Shares Utility\currentshares.txt")
Public strTextFile1, strData1, arrLines1, LineCount1
strTextFile1 = ("C:\Users\a352592\Desktop\Abdullahi\Remove Shares Utility\currentshares.txt")
strData1 = objFSO.OpenTextFile(strTextFile1,ForReading).ReadAll
arrLines1 = Split(strData1,vbCrLf)
LineCount1 = UBound(arrLines1) + 1
wscript.echo "current share count : " &Linecount1
I then need to take the two arrays and take an array item from the current shares and see if it's in the approved shares if not then delete that array and log it. This is the code I was using to compare the two but it doesn't work.
'Compare the two arrays and take out the one's that don't match
For Each ApprovedShareName In arrLines
found = False
For Each CurrentShareName In arrLines1
If ApprovedShareName = CurrentShareName Then
found = True
Exit For
End If
found = False
Next
If found = False Then
'wscript.echo "This isn't on approve shares text : " &textstream2
End If
Next
If arrLines.Contains(CurrentShareName) then
Else
end If
This is the function I was using to delete the line from the txt file
'Set oShell = WScript.CreateObject("WSCript.shell")
'Function oShell (linedelete)
'oShell (linedelete) = oShell.run cmd cd /d C:dir_test\file_test & sanity_check_env.bat arg1
'end Function
This is what was contained in Wscript.shell
/c net.exe share %LINE% /DELETE
This is the files in the approved shares
Test
test123
test1234
flexare
this
is
a
example
This is the files in the current shares
Test
test123
added 1
added2
test1234
flexare
added 3
this
is
a
example
added4
I want the current shares to be just like the approved shares
Test
test123
test1234
flexare
this
is
a
example
With the array files below removed and put in another txt file
added 1
added2
added 3
added4
You want to check if any of the current shares is in the list of approved shares, so you need to switch your inner and outer loop:
VBScript built-in arrays aren't objects, so you can't use something like
You could use an ArrayList object, though:
So your problem is to get the relative complement of the set 'approved' in the set 'current': the set of those elements that are in 'current', but not in 'approved'.
The script:
output:
reads your sample files, computes the relative complement B\A, and writes it to a files.
It uses the diffArray() function from here; this function should go in the file SetLib.vbs in the same folder (the ExecuteGlobal-line 'imports' the function).
The Fi2Ar() function reads the .txt files; I quoted the elements to improve the display, you should remove the statement after testing.