Tcl file checksum matching

1.8k Views Asked by At

I have implemented feature in my tcl/tk project where a file is transferred using fcopy , from windows machine to a VM. Now the problem is the same file is getting copied repeatedly, which is quite unnecessary.

So I have to check if any file with same name already exists in the destination folder. If yes, then I have to make sure that the file content does not match, before aborting the copy procedure. I am aware that check-sum can be used for that but don't know how to implement checksum matching in TCL. Please guide.

3

There are 3 best solutions below

0
On BEST ANSWER

md5 example

md5.tcl

#!/usr/bin/tclsh

package require md5

set fp [open "md5.tcl" r]
set file_data [read $fp]
close $fp

set checksum [md5::md5 -hex $file_data]
puts $checksum

output:

64F63E82282789ACB8F9271CBF35E8B5
1
On

Tcllib in the section Hashes, checksums, and encryption has the functions that you (probably) need. For example checksum.

1
On

you can also use the UNIX command

cksum

this can be invoked well with TCL as

exec cksum <file>

checksum