So I looked up to scripts and realized that I can do an analog via XYplorer scripting language.
I created a script that will calc MD5 checksum for all selected files / folders and save all info in .md5 file (just like TotalCMD do).
I want to share it with you because it may be useful. I appreciate any feedback on it.
Also I'm planning to create the script that will parse this .md5 file and check that all checksums are correct.
Code: Select all
"Calculate MD5 for selected files and folders"
$filelist = getinfo('SelectedItemsPathNames', '|');
$sel_num = getinfo("CountSelected");
if ($sel_num > 0) {
// getting current folder by first file/folder selected
$curdir = gettoken($filelist, 1, "|");
$curdir = gpc($curdir);
if ($sel_num == 1) {
$checksum_file_path = $curdir . "\" . gpc(gettoken($filelist, 1, "|"), "base") . ".md5";
end $checksum_file_path == gettoken($filelist, 1, "|");
}else {
$checksum_file_path = $curdir . "\" . gpc($curdir, "file") . ".md5";
}
status "Getting file list...", , "progress";
$filelist = unwrap_folder_list($filelist);
$file_count = count_items($filelist);
// looping for generated file list
$crc_content = "";
$count = 1;
while(1)
{
$file = gettoken($filelist, $count, "|");
if("$file" == ""){
break;
}
status "Calculating MD5 checksum (" . $count . " of " . $file_count . "): " . gpc($file, "file"), , "progress";
$crc = hash("md5", $file, 3);
$crc_content = $crc_content . $crc . " *" . trim_left($file, strlen($curdir) + 1).chr(13).chr(10);
$count++;
}
writefile($checksum_file_path, $crc_content);
status "Saved MD5 checksum to " . gpc($checksum_file_path, "file");
}
function unwrap_folder_list($file_list) {
//returns file list with only files, recursive for folders in the input
$files_in_curdir = "";
$rez = "";
foreach($token, $file_list, "|") {
if (exists($token) == 2) {
// check for folders
if(strlen($rez) > 0) {
$rez = $rez . "|";
}
$rez = $rez . folderreport("files", "r", gettoken($token, 1, "|"), "r", , "|");
}elseif (exists($token) == 1) {
// check for files
if(strlen($files_in_curdir) > 0) {
$files_in_curdir = $files_in_curdir . "|";
}
$files_in_curdir = $files_in_curdir . $token;
}
}
if((strlen($rez) > 0) and (strlen($files_in_curdir) > 0)) {
$rez = $rez . "|";
}
$rez = $rez . $files_in_curdir;
return $rez;
}
function count_items($list, $sep = "|") {
// counts items in list (f.e. file list)
$count = 0;
foreach($token, $list, $sep) {
$count++;
}
return $count;
}
function trim_left($str, $cnt) {
// trims string by $cnt symbols from the left
return gettoken($str, $cnt + 1, "", , 2);
}