When prompted by IDR to check the integrity of the files we sent to them, they sent us back a text file with the MD5 hashes of each file, which then needed to be compared. This is to ensure integrity of the transfer.
Replace YOURFOLDER
and file-hashes.csv
with the location and names you want.
Get-ChildItem -Path YOURFOLDER -Recurse -Force -File |
Get-FileHash |
Sort-Object -Property 'Path' |
Export-Csv -Path "file-hashes.csv" -NoTypeInformation
You need to install FCIV from Microsoft as per the instruction in that link, then type
fciv YOURFOLDER -r | file-hashes.txt
You can use this Groovy script from Fiji
#@ File idr_file
#@ File local_file
def idr = read_idr_file( idr_file )
def local = read_local_file( local_file )
File result = new File( idr_file.getParent(), "comparison.txt");
idr.each{ file, hash ->
//println( file )
result << file
if (local.containsKey( file )) {
result << "\texists"
if (hash.equals( local.get( file ) ) ) {
result << "\tmatches!"
} else {
result << "\tno match!"
}
} else {
result << "\tlocal file absent"
}
result << "\r\n"
}
return
def read_idr_file( File idr_file ) {
// read all the lines into a list, each line is an element in the list
def lines = idr_file.readLines()
Map<String,String> filehash = new HashMap<>()
Map<String,String> hashfile = new HashMap<>()
lines.each{ line ->
// Split from 0 to 32
def hash = line.substring( 0, 32 ).trim()
// Folder and name start at 34 till the end
def file = line.substring( 34 ).trim()
filehash.put(file, hash)
if ( !hashfile.containsKey( hash ) ) hashfile.put(hash, file )
else println (file + " has same hash as "+ hashfile.get( hash ))
}
return filehash
}
def read_local_file( File local_file ) {
// read all the lines into a list, each line is an element in the list
def lines = local_file.readLines()
Map<String,String> filehash = new HashMap<>()
lines.each{ line ->
// Split from 0 to 32
def hash = line.substring( 0,32 ).trim()
// Folder and name start at 45 ( remove 'marroquant' ) and make slashes unix like
def file = line.substring( 45 ).trim().replace("\\", "/")
filehash.put( file, hash )
}
return filehash
}