-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChecksumInFolder.xys
54 lines (50 loc) · 1.92 KB
/
ChecksumInFolder.xys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
::/** XYplorer: Generate folders checksums
Creates a MD5 checksum file for the current or selected files folder.
Select files or subfolders in a folder to be indexed. It will scan the selection recursively and generate a md5 checksum file in the base folder.
The checksum file will be like [folder-name].md5 .
It will replace the checksum file if there is already a checksum in it. The checksum also ignores any selected .md5 or .sfv files.
At the end, it shows the execution log.
@author rdoi
@created feb/2014
*/
$log="ChecksumInFolder.xys: RDoi MD5 checksum creator<crlf>-------------------------------<crlf>";
$folder=get("Path");
$log=$log."Processing '".$folder."' items...<crlf>";
if (get("CountSelected") == 0) {
$flist= folderreport("files", "r", $folder, "r", , "<crlf>");
} else {
$flist= "";
foreach($item, get("SelectedItemsPathNames"), "<crlf>") {
if (exists($item) == 2) {
$flist= $flist. folderreport("files", "r", $item, "r", , "<crlf>")."<crlf>";
} else {
$flist= $flist.$item."<crlf>";
}
}
}
$csfile=$folder."\".regexreplace($folder,"^.*\\", "").".md5";
$template="; MD5 checksum generated by RDOI XYplorer script<crlf>; ".$folder."<crlf>";
$checksum=$template;
foreach($file, $flist, "<crlf>") {
if ($file != "") {
$rfile= replace($file,$folder."\","");
if ( regexmatches($rfile,"(\.md5|\.sfv)$") == "") {
$hash=hash("md5",$file,3);
$checksum=$checksum.$hash." *".$rfile."<crlf>";
$log=$log."+ ".$rfile." [".$hash."]<crlf>";
} else {
$log=$log."-IGNORED: Checksum file. (".$rfile.")<crlf>";
}
}
}
if ($checksum == $template) {
$log=$log."No valid files selected.<crlf>=CANCELLED.";
} else {
if (exists($csfile) > 0) {
$log=$log."=REPLACED. (".$csfile.")<crlf>";
} else {
$log=$log."=CREATED. (".$csfile.")<crlf>";
}
writefile($csfile,$checksum);
}
text $log;