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