Browse Source

增加 3个 提供学习的脚本

liuyuqi-dellpc 4 years ago
parent
commit
338dad0355
3 changed files with 117 additions and 0 deletions
  1. 54 0
      ChecksumInFolder.xys
  2. 39 0
      ChecksumsInFolders.xys
  3. 24 0
      RemoveEmptyFolders.xys

+ 54 - 0
ChecksumInFolder.xys

@@ -0,0 +1,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;

+ 39 - 0
ChecksumsInFolders.xys

@@ -0,0 +1,39 @@
+::/** XYplorer: Generate folders checksums
+
+Creates a MD5 checksum file for selected folders.
+Just select some folders in any panel and run. It will scan all subfiles/subfolders within and generate a md5 checksum file in each folder.
+The checksum file will be like [folder-name].md5 .
+It will ignore the folder if there is already a checksum in it. The checksum also ignores any existing .md5 or .sfv files.
+
+At the end, it shows the execution log.
+
+@author rdoi
+@created feb/2014
+*/
+		$log="ChecksumsInFolders.xys: RDoi folders MD5 checksum creator<crlf>-------------------------------<crlf>";
+		foreach($folder, "<get SelectedItemsPathNames>", "<crlf>") {
+			$log=$log."Processing ".$folder."...<crlf>";
+			if (exists($folder) == 1) {
+				$log=$log."-SKIPPED: Not a folder.<crlf>";
+			} else {
+				$csfile=$folder."\".regexreplace($folder,"^.*\\", "").".md5";
+				if (exists($csfile) == 1) {
+					$log=$log."-IGNORED: Checksum exists. (".$csfile.")<crlf>";
+				} else {
+					$checksum="; MD5 checksum generated by RDOI XYplorer script<crlf>; ".$folder."<crlf>";
+					foreach($file, folderreport("filesrel", "r", $folder, "r", , "|"), "|") {
+						$filepath=$folder."\".$file;
+						if ( regexmatches($filepath,"(\.md5|\.sfv)$") == "") {
+							$hash=hash("md5",$filepath,3);
+							$checksum=$checksum.$hash." *".$file."<crlf>";
+						} else {
+							$log=$log."-IGNORED: Checksum file. (".$filepath.")<crlf>";
+						}
+					}
+					writefile($csfile,$checksum);
+					$log=$log."+CREATED. (".$csfile.")<crlf>";
+				}
+			}
+			$log=$log."<crlf>";
+		}
+		text $log;

+ 24 - 0
RemoveEmptyFolders.xys

@@ -0,0 +1,24 @@
+::/** XYplorer: Remove Empty Folders
+
+Remove recursively all empty folder from the current folder.
+At the end, it shows the execution log.
+
+@author rdoi
+@created feb/2014
+*/
+		$log="RemoveEmptyFolders.xys: RDoi Empty folders remover<crlf>-------------------------------<crlf>";
+		$folder=get("Path");
+		$log=$log."Processing '".$folder."' folders...<crlf>";
+		$flist=formatlist(folderreport("dirs","r",$folder,"r",,"|"),"r","|")."|".$folder;
+		$count=0;
+		foreach($f, $flist,"|") {
+			$content=listfolder($f,,0,"|");
+			if ($content=="") {
+			  delete 0,0,$f;
+				$log=$log."Removed: ".$f."<crlf>";
+				$count=$count+1;
+			}
+		}
+		$log=$log.">>> ".$count." folders removed.";
+		beep;
+		text $log;