i wasn't planning on posting this, but it's similar, so here it goes.
it's a script i've been using to calculate checksums from files.
it uses fsum.exe from
this site.
fsum.exe must be in the %systemroot% folder.
if there are files selected it will calculate their checksum.
if nothing is selected it will calculate checksums for all files in current folder and, optionally, subfolders.
the last subscript is supposed to get the checksums (crc32 by default) and put it on a global variable, but i never used it before, so i'm not sure if it works.
p.s.: i'm too lazy to put comments on the script.
Code: Select all
"Calculate CRC32 : calculatecrc"
if(getinfo(countselected)<1){
$recurse=confirm("Look for files inside subdirectories?")?("-r"):("");
run "cmd /k """"<xypath>\tools\fsum.exe"" $recurse -crc32 -jnc -jm -d""<curpath>"" *.*""";}
else{
$files=report("{Dir | ""{fullpath}\{name}""|}",1);
if("$files"==""){end 1, "No files selected.";}
strlen $len, $files;
if($len>8000){
$files=report("{dir | ""{name}""|}",1);
run "cmd /k """"<xypath>\tools\fsum.exe"" -r -crc32 -jnc -jm -d""<curpath>"" $files""";
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /k """"<xypath>\tools\fsum.exe"" -crc32 -jnc -jm$files""";}}
"Save CRC32 to sfv : savecrc"
$count=getinfo(countselected);
if($count<1){
$recurse=confirm("Look for files inside subdirectories?")?("-r"):("");
run "cmd /c """"<xypath>\tools\fsum.exe"" $recurse -crc32 -jnc -js -d""<curpath>"" *.* >""<curfolder>_crcsums.sfv""""";}
else{
$sfvname=($count==1)?("<curname>"):("<curfolder>_crcsums");
$items=report("{Dir | ""{fullpath}\{name}""|}",1);
if("$items"==""){end 1, "No files selected.";}
$files=$items." >""<curpath>\$sfvname.sfv""";
strlen $len, $files;
if($len>8000){
$files=report("{dir |""{name}"" |}",1);
run "cmd /c """"<xypath>\tools\fsum.exe"" -r -crc32 -jnc -js -d""<curpath>"" $files""";
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /c """"<xypath>\tools\fsum.exe"" -r -crc32 -jnc -js$files""";}}
"Check CRC32 from name : checkcrcfromname"
end (getinfo(countselected)<1),"Nothing selected";
$list=report("{dir |{fullpath}\{name}<crlf>|}",1);
if("$list"==""){end 1, "No files selected.";}
regexreplace $list,$list,"^(.+[\[\(_])([A-Fa-f0-9]{8})([\)\]_].+)\r\n","$1$2$3 $2<crlf>";
writefile("%temp%\crcsumfromname.sfv",$list);
run 'cmd /K """<xypath>\tools\fsum.exe"" -r -w -c "%temp%\crcsumfromname.sfv""';
-
"Calculate MD5 : calculatemd5"
if(getinfo(countselected)<1){
$recurse=confirm("Look for files inside subdirectories?")?("-r"):("");
run "cmd /k """"<xypath>\tools\fsum.exe"" $recurse -md5 -jnc -jm -d""<curpath>"" *.*""";}
else{
$files=report("{Dir | ""{fullpath}\{name}""|}",1);
if("$files"==""){end 1, "No files selected.";}
strlen $len, $files;
if($len>8000){
$files=report("{dir | ""{name}""|}",1);
run "cmd /k """"<xypath>\tools\fsum.exe"" -r -md5 -jnc -jm -d""<curpath>"" $files""";
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /k """"<xypath>\tools\fsum.exe"" -r -md5 -jnc -jm$files""";}}
"Save MD5 to md5 : savemd5"
$count=getinfo(countselected);
if($count<1){
$recurse=confirm("Look for files inside subdirectories?")?("-r"):("");
run "cmd /c """"<xypath>\tools\fsum.exe"" $recurse -md5 -jnc -jm -d""<curpath>"" *.* >""<curfolder>_md5sums.md5""""";}
else{
$sfvname=($count==1)?("<curname>"):("<curfolder>_md5sums");
$items=report("{Dir | ""{fullpath}\{name}""|}",1);
if("$items"==""){end 1, "No files selected.";}
$files=$items." >""<curpath>\$sfvname.md5""";
strlen $len, $files;
if($len>8000){
$files=report("{dir |""{name}"" |}",1);
run "cmd /c """"<xypath>\tools\fsum.exe"" -r -md5 -jnc -jm -d""<curpath>"" $files""";
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /c """"<xypath>\tools\fsum.exe"" -r -md5 -jnc -jm$files""";}}
-
"Other checksums : other"
$count=getinfo(countselected);
if($count>0){
$items=report("{Dir | ""{fullpath}\{name}""|}",1);
end ("$items"==""), "No files selected.";
$disabled=disabled;$disabled2="";}
else{$disabled2=disabled;$disabled="";}
$html=<<<HTML
<html>
<body>
<h4 style="text-align:center">Select checksums to calculate</h4>
<form action="xys:" method="get" style="font-size:13px">
<input type="checkbox" name="alg" value="crc32"> CRC32<br />
<input type="checkbox" name="alg" value="md2"> MD2<br />
<input type="checkbox" name="alg" value="md4"> MD4<br />
<input type="checkbox" name="alg" value="md5"> MD5<br />
<input type="checkbox" name="alg" value="sha1"> SHA-1<br />
<input type="checkbox" name="alg" value="sha256"> SHA-2 (256)<br />
<input type="checkbox" name="alg" value="sha384"> SHA-2 (384)<br />
<input type="checkbox" name="alg" value="sha512"> SHA-2 (512)<br />
<input type="checkbox" name="alg" value="edonkey"> EDONKEY<br />
<input type="checkbox" name="alg" value="tiger"> TIGER<br />
<input type="checkbox" name="alg" value="rmd"> RIPEMD-160<br />
<input type="checkbox" name="alg" value="panama"> PANAMA<br />
<input type="checkbox" name="alg" value="adler"> ADLER32<br />
<br />
Look inside subdirectories?<br />
<input type="hidden" name="rec" value="0" $disabled2>
<input type="radio" name="rec" value="1" $disabled> Yes <input type="radio" name="rec" value="0" checked $disabled> No<br />
<br />
<input type="submit" name="act" value="Calculate" /> <input type="submit" name="act" value="Save to file" />
</form>
</body>
</html>
HTML;
replace $input,html($html,320,510),"?","&";
$alg=gettoken($input,1,"&rec=");
if("$alg"==""){end 1;}
replace $alg,$alg,"&alg="," -";
$act=gettoken($input,2,"&act=");
regexreplace $rec,$input,"^.*?&rec=(\d).+$","$1";
if("$act"=="Calculate"){$save=0; $kp=k;}
else{$save=1; $kp=c;}
if($count<1){
$rec=($rec==1)?("-r"):("");
run "cmd /$kp """"<xypath>\tools\fsum.exe"" $rec$alg -jnc -jm -d""<curpath>"" *.*".($save==1)?(" >""<curfolder>_checksums.md5"""""):('""');}
else{
$sfvname=($count==1)?("<curname>"):("<curfolder>_checksums");
$files=($save==1)?("$items >""<curpath>\$sfvname.md5"""):($items);
strlen $len, $files;
if($len>8000){
$files=report("{dir | ""{name}""|}",1);
run "cmd /$kp """"<xypath>\tools\fsum.exe"" $alg -jnc -jm -d""<curpath>""$files ".($save==1)?(">""$sfvname.md5"""""):('""');
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /$kp """"<xypath>\tools\fsum.exe"" $alg -jnc -jm$files""";}}
"Get Checksum : _getchecksum"
global $getchecksum;
if("$getchecksum"==""){$getchecksum="-crc32";} // crc32 md5 sha1 edonkey
end (getinfo(countselected)<1),"Nothing selected";
$items=report("{Dir | ""{fullpath}\{name}""|}",1);
if("$items"==""){end 1, "No files selected.";}
$files=$items.' >"%temp%\checksums.tmp"';
strlen $len, $files;
if($len>8000){
$files=report("{dir |""{name}"" |}",1);
run "cmd /c """"<xypath>\tools\fsum.exe"" -r $getchecksum -jnc -d""<curpath>"" $files>""$sfvname.md5""""",1;
status "Warning! Exceeded command line lenght limit!",ffff00,alert;}
else{run "cmd /c ""<xypath>\tools\fsum.exe"" -r $getchecksum -jnc$files""",1;}}
$getchecksum=readfile("%temp%\checksums.tmp");
-
"Cancel"
end 1;
--------
ale wrote:My problem is that I really fight with quotes and I didn't fully grasp their use in complex situations, how and when the XY script parser eat them and so on
yup, quotes can be a real pain some times.
i'm sure there's an explanation on how to use them somewhere in the wiki, but my internet is so crappy today that i can't even open that page.
your "run" command had some misplaced quotes when i tested it.
i
think it should be like this:
Code: Select all
run "$hstart $parameters """"%SystemRoot%\system32\cmd.exe"" /c ""$sha1sum"" ""<curitem>"" | ""$clip""""", , 1;
use the debug window to see if the quotes are in the right places.