Leer un archivo y comparar

Hola!:
Me gustaría saber como se puede leer información de un archivo de texto y compararla con una base de datos desde una página web.
Gracias.

1 respuesta

Respuesta
1
Utiliza este código que compara dos archivos de texto y saca un tercer archivo con las diferencias. Puedes aplicarlo igual, sustituyendo el segundo archivo que compara, con el valor que optienes de base de datos:
Const ForAppending = 8
Const ForWriting = 2
Const ForReading=1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Source file #1. Change the path and file name.
Set objFile1 = objFSO.OpenTextFile("C:\file1.txt", ForReading)
'Reads the entire contents of File1 into a string variable.
sContents1=objFile1.ReadAll
objFile1.Close
'Source file #2. Change the path and file name.
Set objFile2 = objFSO.OpenTextFile("C:\file2.txt", ForReading)
'Reads the entire contents of File2 into a string variable.
sContents2=objFile2.ReadAll
objFile2.Close
'Output file, contains the list of differences between Source file #1 and Source file #2. Change the path and file name.
'Warning! This will overwrite File3 everytime the script is run. If the output file (File3) isn't found, then it will be created.
If objFSO.FileExists("C:\file3.txt") Then
Set objFile3 = objFSO.OpenTextFile("C:\file3.txt", ForWriting)
Else
Set objFile3 = objFSO.CreateTextFile("C:\file3.txt")
End If
Set objFile1 = objFSO.OpenTextFile("C:\file1.txt", ForReading)
'Reads each line of File1 and searches for a match in the variable containing the contents of File2
Do Until objFile1.AtEndOfStream
strComputer = objFile1.ReadLine
'If the line from File1 can't be found in File2, then it will right the line to File3
If InStr(sContents2, strComputer) = 0 then
objFile3.WriteLine (strComputer)
End If
'Clears the variable
strComputer = ""
Loop
objFile1.Close
Set objFile2 = objFSO.OpenTextFile("C:\file2.txt", ForReading)
''Reads each line of File2 and searches for a match in the variable containing the contents of File1
Do Until objFile2.AtEndOfStream
strComputer = objFile2.ReadLine
'If the line from File2 can't be found in File1, then it will right the line to File3
If InStr(sContents1, strComputer) = 0 then
objFile3.WriteLine (strComputer)
End If
'Clears the variable
strComputer = ""
Loop
'Closes the open files
ObjFile2. Close
ObjFile3. Close
No olvides cerrar la pregunta para que otros me puedan preguntar!.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas