所以我创建了这两个数组 Approved share 和 current share。
'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
然后我需要获取这两个数组并从当前共享中获取一个数组项,看看它是否在批准的共享中,如果不是,则删除该数组并记录它。这是我用来比较两者的代码,但它不起作用。
'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
这是我用来从 txt 文件中删除该行的函数
'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
这是 Wscript.shell 中包含的内容
/c net.exe share %LINE% /DELETE
这是已批准共享中的文件
Test
test123
test1234
flexare
this
is
a
example
这是当前共享中的文件
Test
test123
added 1
added2
test1234
flexare
added 3
this
is
a
example
added4
我希望当前股票与已批准的股票一样
Test
test123
test1234
flexare
this
is
a
example
删除下面的数组文件并放入另一个 txt 文件
added 1
added2
added 3
added4