View Single Post
  #724  
Old 15.05.2019, 08:05
sherbee sherbee is offline
Junior Loader
 
Join Date: Mar 2019
Posts: 12
Default

Quote:
Originally Posted by mgpai View Post
Here is a new script, but if you need help to troubleshoot/fix yours, contact me in JD Chat.

Code:
// Move archive files after extraction
// Trigger: Archive Extraction Finished

var links = archive.getDownloadLinks() || [];
var destinationFolder = "C:/sherbee/check";

links.forEach(function(link) {
    var filePath = getPath(link.getDownloadPath());
    var i = 0;

    while (getPath(destinationFolder + "/" + filePath.getName()).exists()) {
        i++;
        newPath = getPath(link.getDownloadPath().toString().replace(/(.+)(\..+)/, "$1" + i + "$2"));
        getPath(filePath).renameTo(newPath);
        filePath = newPath;
    }

    filePath.moveTo(destinationFolder);
});
I think this is very good. Thank you. I understand better now. Replace with regex is very clever.

2 Questions I have:
  1. Is there more docu to understand better return of methods? For example if I put
    Code:
    var myString = myFilePath.getPath();
    Is output with "\" or with "/" or has it slash at end. Or when I put
    Code:
    var myString = myFilePath.getExtension();
    is output with "." or without? That is make it more easy to know better what exactly is return not only return type. Then more easy to use and put back together.
  2. Code:
    newPath = getPath(link.getDownloadPath().toString().replace(/(.+)(\..+)/, "$1" + i + "$2"));
    Is link.getDownloadPath() not string type already? Why you put ".toString()"? I think that is the only thing I cannot understand now.
All other is so very good that I want to my head for better thinking.

Only thing I must change is
Code:
replace(/(.+)(\..+)/, "$1" + i + "$2"));
to
Code:
replace(/(.+)(\..+)/, "$1 (" + i + ")$2"));
then it is like Windows Explorer original rename.
Reply With Quote