I was told by the developer that it was possible to implement the ability to insert/crop CRC32 values from filenames via context menu with the help of scripting.
In practice, selecting the context menu's "Rename Special">"Insert CRC32" would append the selected file(s) checksum value after the filename (e.g. filename-b8ab44fa.txt)
An additional "Crop CRC32" entry would be necessary for the removal of CRC values from filesnames.
There's a no-install application called LupasRename (https://rename.lupasfreeware.org/) that can be used to achieve this but implementing this ability into XYplorer file naming options would be a huge assist to productivity if third-party apps were no longer needed.
I'd appreciate as much help as possible in creating a script that adds this functionality to XYplorer, thank you in advance.
[REQ]Rename Special>Insert/Crop CRC32 Checksum Value From Filename
Re: [REQ]Rename Special>Insert/Crop CRC32 Checksum Value From Filename
You can't add this to the rename special inbuilt menu
Use a "Run script" action for "Middle-click on file" in "Configuration | General | Custom Event Actions"
Use a "Run script" action for "Middle-click on file" in "Configuration | General | Custom Event Actions"
Code: Select all
$lcaseHash = true;
$files = <get SelectedItemsPathNames>;
end (!$files), "No file(s) selected, aborted!";
$menu = <<<>>>
Add CRC32 hash(es)|add|:tagsadd
Remove CRC32 hash(es)|remove|:tagsrmv
>>>;
$menu = regexreplace($menu, "^[ \t]+");
$sel = popupmenu($menu, 6:=<crlf>, 7:="|");
if ($sel) {
if ($sel == "add") { HandleCRC32($files, "add", $lcaseHash); }
elseif ($sel == "remove") { HandleCRC32($files, "remove", $lcaseHash); }
}
function HandleCRC32($files, $cmd="add", $lcase=true) {
showstatus 0;
foreach($file, $files, <crlf>, "e") {
if (exists($file) == 2) { continue; }
$base = gpc($file, "base");
$ext = gpc($file, "ext");
if ($cmd == "add") {
if (regexmatches($base, "-[a-f0-9]{8}$")) {
$base = regexreplace($base, "-[a-f0-9]{8}$");
}
status "Calculating hash: " . gpc($file, "file"), , "progress";
$hash = hash("crc32", $file, 1);
if ($lcase) { $hash = recase($hash, "l"); }
renameitem($base . "-" . $hash . "." . $ext, $file);
} elseif ($cmd == "remove") {
if (regexmatches($base, "-[a-f0-9]{8}$")) {
$base = regexreplace($base, "-[a-f0-9]{8}$");
renameitem($base . "." . $ext, $file);
}
}
}
status "All done...";
}
One of my scripts helped you out? Please donate via Paypal
Re: [REQ]Rename Special>Insert/Crop CRC32 Checksum Value From Filename
Amazing. Thank you for posting this script. Opens up a lot of ideas that can be done with this as a template.