Good night people!
I am new to the forum and I have a doubt this code below needs to read 2 files compare them line by line, after comparing all I have to move them to another directory, go back and read two more and so will even read all the files can help me please.
Obs: I'm sorry if I couldn't open a question like this, I need some urgent help neutral
Following code below:
'###################################################################################
' Autor: Renan
' E-mail:
' Data Criação: 04/10/2019
'###################################################################################
' Objetivo: Compara 2 arquivos .txt linha à linha
'###################################################################################
' Modificações:
'###################################################################################
'on error resume next
'SystemUtil.Run "C:\Scripts\CONVERSOR\ReleaseConversor\ParquetConversor.exe"
ARR = array ("txt")
srcFldr = "C:\Scripts\arquivos\comparar\"
destFldr = "C:\Scripts\arquivos\backup\"
'destFldr = f.GetParentFolderName(WScript.ScriptFullName) & "\"
Set fs1 = CreateObject("Scripting.FileSystemObject")
Set fs2 = CreateObject("Scripting.FileSystemObject")
Set f = fs1.GetFolder(srcFldr)
Set fc = f.Files
For a = 0 To ubound (arr)
For each fs1 in fc
'If Right (f1.name, 3) = arr (a) then f1.copy destFldr
If fs1.name <> "" and Arqu1 = "" Then
Arq1 = fs1.name
PathArq1 = srcFldr & fs1.name
'fs.MoveFile PathArq1, destFldr
End If
For each fs2 in fc
varArq1 = Mid(Arq1, 1, 6)
If Arq1 <> fs2.name and Instr(f2.name, varArq1) Then
Arq2 = fs2.name
PathArq2 = srcFldr & fs2.name
'fs.MoveFile PathArq2, destFldr
Exit for
End If
Next
strArquivo1 = srcFldr & Arq1
strArquivo2 = srcFldr & Arq2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArquivo1 = objFSO.OpenTextFile(strArquivo1, 1)
Set objArquivo2 = objFSO.OpenTextFile(strArquivo2, 1)
Different = 0
nTotalLinha1 = UBound(Split(objFSO.OpenTextFile(strArquivo1).ReadAll, vbLf))
nTotalLinha2 = UBound(Split(objFSO.OpenTextFile(strArquivo2).ReadAll, vbLf))
if ( nTotalLinha2 > nTotalLinha1 ) Then
nTotal = nTotalLinha2
Else
nTotal = nTotalLinha1
End If
' MsgBox "[+] Comparando linhas dos arquivos..."
'Reporter.ReportEvent micPass, Environment("ComparaArquivo"), "[+] Comparando linhas dos arquivos..."
nLinha = 0
Do Until objArquivo2.AtEndOfStream
strLinha2 = objArquivo2.ReadLine
strLinha1 = objArquivo1.ReadLine
' if err.number <> 0 Then strLinha1 = "" End If
If nLinha = nTotal Then
fs1.MoveFile PathArq1, destFldr
fs2.MoveFile PathArq2, destFldr
ElseIf strLinha2 <> strLinha1 Then
Reporter.ReportEvent 1, "comparando arquivos", "Arquivo: " & Arq2 & " - Linha "& nLinha &" : " & strLinha2 & " É diferente!"
Different = 1
ElseIf nLinha = nTotal and Different <> 1 Then
Reporter.ReportEvent 0, "comparando arquivos", "Arquivos: " & Arq1 & " e " & Arq2 & " são Exatamente iguais!"
fs1.MoveFile PathArq1, destFldr
fs2.MoveFile PathArq2, destFldr
End If
nLinha = nLinha + 1
Loop
'fs.MoveFile PathArq1, destFldr
'fs.MoveFile PathArq2, destFldr
Next
Next
Set f = nothing
Set fc = nothing
Set fs1 = nothing
Set fs2 = nothing
'Print "---------------------------------------------"
'Print " Arquivo 1: ( " & nTotalLinha1 & " )"
'Print " Arquivo 2: ( " & nTotalLinha2 & " )
I am new to the forum and I have a doubt this code below needs to read 2 files compare them line by line, after comparing all I have to move them to another directory, go back and read two more and so will even read all the files can help me please.
Obs: I'm sorry if I couldn't open a question like this, I need some urgent help neutral
Following code below:
'###################################################################################
' Autor: Renan
' E-mail:
' Data Criação: 04/10/2019
'###################################################################################
' Objetivo: Compara 2 arquivos .txt linha à linha
'###################################################################################
' Modificações:
'###################################################################################
'on error resume next
'SystemUtil.Run "C:\Scripts\CONVERSOR\ReleaseConversor\ParquetConversor.exe"
ARR = array ("txt")
srcFldr = "C:\Scripts\arquivos\comparar\"
destFldr = "C:\Scripts\arquivos\backup\"
'destFldr = f.GetParentFolderName(WScript.ScriptFullName) & "\"
Set fs1 = CreateObject("Scripting.FileSystemObject")
Set fs2 = CreateObject("Scripting.FileSystemObject")
Set f = fs1.GetFolder(srcFldr)
Set fc = f.Files
For a = 0 To ubound (arr)
For each fs1 in fc
'If Right (f1.name, 3) = arr (a) then f1.copy destFldr
If fs1.name <> "" and Arqu1 = "" Then
Arq1 = fs1.name
PathArq1 = srcFldr & fs1.name
'fs.MoveFile PathArq1, destFldr
End If
For each fs2 in fc
varArq1 = Mid(Arq1, 1, 6)
If Arq1 <> fs2.name and Instr(f2.name, varArq1) Then
Arq2 = fs2.name
PathArq2 = srcFldr & fs2.name
'fs.MoveFile PathArq2, destFldr
Exit for
End If
Next
strArquivo1 = srcFldr & Arq1
strArquivo2 = srcFldr & Arq2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArquivo1 = objFSO.OpenTextFile(strArquivo1, 1)
Set objArquivo2 = objFSO.OpenTextFile(strArquivo2, 1)
Different = 0
nTotalLinha1 = UBound(Split(objFSO.OpenTextFile(strArquivo1).ReadAll, vbLf))
nTotalLinha2 = UBound(Split(objFSO.OpenTextFile(strArquivo2).ReadAll, vbLf))
if ( nTotalLinha2 > nTotalLinha1 ) Then
nTotal = nTotalLinha2
Else
nTotal = nTotalLinha1
End If
' MsgBox "[+] Comparando linhas dos arquivos..."
'Reporter.ReportEvent micPass, Environment("ComparaArquivo"), "[+] Comparando linhas dos arquivos..."
nLinha = 0
Do Until objArquivo2.AtEndOfStream
strLinha2 = objArquivo2.ReadLine
strLinha1 = objArquivo1.ReadLine
' if err.number <> 0 Then strLinha1 = "" End If
If nLinha = nTotal Then
fs1.MoveFile PathArq1, destFldr
fs2.MoveFile PathArq2, destFldr
ElseIf strLinha2 <> strLinha1 Then
Reporter.ReportEvent 1, "comparando arquivos", "Arquivo: " & Arq2 & " - Linha "& nLinha &" : " & strLinha2 & " É diferente!"
Different = 1
ElseIf nLinha = nTotal and Different <> 1 Then
Reporter.ReportEvent 0, "comparando arquivos", "Arquivos: " & Arq1 & " e " & Arq2 & " são Exatamente iguais!"
fs1.MoveFile PathArq1, destFldr
fs2.MoveFile PathArq2, destFldr
End If
nLinha = nLinha + 1
Loop
'fs.MoveFile PathArq1, destFldr
'fs.MoveFile PathArq2, destFldr
Next
Next
Set f = nothing
Set fc = nothing
Set fs1 = nothing
Set fs2 = nothing
'Print "---------------------------------------------"
'Print " Arquivo 1: ( " & nTotalLinha1 & " )"
'Print " Arquivo 2: ( " & nTotalLinha2 & " )