drrob1 wrote:
|
| An example would make this clearer
| I have this file, we'll call it UbuntuHashes.txt. The contents are thus:
|
| ubuntu-9.10-desktop-amd64.iso
| dc51c1d7e3e173dcab4e0b9ad2be2bbf
| ubuntu-9.10-desktop-i386.iso
| 8790491bfa9d00f283ed9dd2d77b3906
|
| I have already downloaded the 2 iso files listed here. Each is meant to
| fill a cd, so it is ~ 700 MB in size. I want to be able to select this
| UbuntuHashes.txt file and have the md5 hash computed for the iso and
| checked against the value provided by Canonical.
|
| I did get this to work:
| batchmd5.btm
| set filespec=%@getfile[.]
| set md5hash=%@md5[f,%@line[%filespec,0]]
|
| IFF %md5hash EQ %@line[%filespec,1] THEN
| echo Matched
| ELSE
| echo Not Matched
| ENDIFF
I will assume that the file listing filenames and hashcodes is short,
so that reading the file n! times (if it has n lines) is still
reasonable. Let the filename be passed as the only parameter to the
file below:
--- begin code ---
@echo off
setlocal
set hashlist=%@getfile[.]
do n = 0 to %@lines[%hashlist] by 2
set file=%@line[%hashlist,%n]
set hash=%@line[%hashlist,%@inc[%n]]
echo %@if[ %hash == %@md5[f,%file] ,OK ,BAD] %file
enddo
--- end code ---
If you have many lines to deal with, using DO's capability to process
consecutive lines of a file can be utilized:
--- begin code ---
@echo off
setlocal
set hashlist=%@getfile[.]
set next=file
do line in @hashlist
switch %next
case file
set file=%@line[%hashlist,%n]
set next=hash
case hash
set hash=%@line[%hashlist,%@inc[%n]]
echo %@if[ %hash == %@md5[f,%file] ,OK ,BAD] %file
set next=file
enddo
--- end code ---
|
| One thing puzzles me though. The help file says that @getfile has been
| replaced by the more powerful @getfolder. But I don't want a
| foldername, I want a filename.
I think this should have been a qualified statement, applicable only
when the desired item may be a folder instead of a file.
| I am also confused by the line that not
| all folders are directories, as I use the term interchangably.
In MS terminology, folders represent a collection of items, some of
which may be folders themselves, none of which need to have an
explicit mapping to directories in any of the disk volumes. For
example, the folder My Computer includes everything about the
computer, not just the contents of its individual disk volumes, yet
there is nowhere in the file system an entity named "My Computer".
--
HTH, Steve