Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare 2 file then move them from directory - VbScript

Status
Not open for further replies.

renangt

Programmer
Oct 11, 2019
3
BR
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 G. Teixeira
' 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 fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(srcFldr)
Set fc = f.Files

For a = 0 To ubound (arr)

For each f1 in fc
'If Right (f1.name, 3) = arr (a) then f1.copy destFldr
If f1.name <> "" and Arqu1 = "" Then
Arq1 = f1.name
PathArq1 = srcFldr & f1.name
'fs.MoveFile PathArq1, destFldr
End If
For each f2 in fc
varArq1 = Mid(Arq1, 1, 6)
If Arq1 <> f2.name and Instr(f2.name, varArq1) Then
Arq2 = f2.name
PathArq2 = srcFldr & f2.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)

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 strLinha2 <> strLinha1 Then
' Print "Linha "& nLinha &" : " & strLinha2
Reporter.ReportEvent 1, "comparando arquivos", "Arquivo: " & Arq2 & " - Linha "& nLinha &" : " & strLinha2 & " É diferente!"
Exit Do
Else
Reporter.ReportEvent 0, "comparando arquivos", "Arquivos: " & Arq1 & " e " & Arq2 & " são Exatamente iguais!"
End If

nLinha = nLinha + 1

Loop
'fs.MoveFile PathArq1, destFldr
'fs.MoveFile PathArq2, destFldr

Next
Next

Set f = nothing
Set fc = nothing
Set fs = nothing

'Print "---------------------------------------------"
'Print " Arquivo 1: ( " & nTotalLinha1 & " )"
'Print " Arquivo 2: ( " & nTotalLinha2 & " )
 
VbScript queries are probably better dealt with in forum329
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top