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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for comparing files 1

Status
Not open for further replies.

ufriends

IS-IT--Management
Jul 25, 2008
2
US
Hi,
I am in need of a script as mentioned below:

Input: File names, versions, size (All can be supplied by a text file, Files may be in different folders in C: drive)

Output:It should check for the files (supplied as input)and if file is present it should check for version and size. If it finds any difference then it should generate the output as like size was different for particular file.

Thanks,
Uttam
 
Something similar to this script structure might be able to help you out.

Just create a text file (titled "List.txt" within same directory as the script.

Then in the text file arrange the lines as:

1st line: File Name (EXAMPLE: "C:\Windows\System32\<YourFile>")
2nd line: Version (EXAMPLE: 1.0.0.1)
3rd line: Size (EXAMPLE: 1523 [1523 = 1.48KB]) 'The size is calculate in bytes...that can be changed if need be.

If you have two or more files to check just continue the lines within the text file.

File one consists of lines 1 ~ 3
File two consists of lines 4 ~ 6
File three consists of lines 7 ~ 9
etc, etc.

----------------------------------------------------
option explicit

Const ForReading = 1

Dim strScriptPath, strFileName, strDirectory
Dim objFileSO, objLogFile, objTextFile

strScriptPath = Wscript.ScriptFullName

strFileName = "List.txt"

Set objFileSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFileSO.GetFile(strScriptPath)

strDirectory = objFileSO.GetParentFolderName(objLogFile) & "\" & strFileName

Set objTextFile = objFileSO.OpenTextFile(strDirectory, ForReading, True)

Do until objTextFile.AtEndOfStream

FileNames = objTextFile.Readline
Versions = objTextFile.Readline
Size = objTextFile.Readline


Input(FileNames,Versions,Size)

Loop

CleanMemory

wscript.echo "Done!"
Wscript.Quit

Sub Input(FileNames,Versions,Size)
Dim FSO, File, strSize, FileNames, WshShell

Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.GetFile(FileNames)

If File.Version <> Versions Then

Wscript.echo FileNames & " version was found to be different."

End If

If File.Size <> Size Then

Wscript.echo FileNames & " size was found to be different."

End If

Set File = Nothing
Set FSO = Nothing
Set strSize = Nothing
Set FileNames = Nothing
Set WshShell = Nothing

End Sub

Sub CleanMemory
Set FileNames = Nothing
Set Versions = Nothing
Set Size = Nothing
Set strScriptPath = Nothing
Set strFileName = Nothing
Set strDirectory
Set objFileSO = Nothing
Set objLogFile = Nothing
Set objTextFile = Nothing
End Sub

V/r,

SPC Key
United States Army
 
Hi,
Thanks for your reply.

But when I try to execute the script it gives me error for sub Input. It says for sub it cant take parantheses.

Please have a look.

Thanks,
Uttam
 
>Input(FileNames,Versions,Size)
Either
[tt]Input FileNames,Versions,Size[/tt]
or
[tt]call Input(FileNames,Versions,Size)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top