Quote:
Originally Posted by mgpai
One option would be to move the files to a timestamp based sub-folder.
Code:
// Move archive files after extraction
// Trigger: Archive Extraction Finished
var links = archive.getDownloadLinks() || [];
var timestamp = new Date().getTime();
links.forEach(function(link) {
var filePath = getPath(link.getDownloadPath());
filePath.moveTo(filePath.getParent().toString().replace("JD Downloads", "!TRASH!/" + timestamp));
});
|
Thank you for idea. But I like complicated.
So new folder not good.
I made very silly code but maybe its work? Can you help me? I put many comments so you can understand easy what I think.
Code:
const MOVETODIR = "C:\\sherbee\\check"; //Set dir for move destination
var links = archive.getDownloadLinks() || [];
links.forEach(function(link) {
var filePath = getPath(link.getDownloadPath());
var fileName = myFilePath.getName(); //Get name of file
var fileExtension = myFilePath.getExtension(); //Get extension of file
var fileMoveCheck = MOVETODIR + '\\' + fileName + "." + fileExtension; //Build absolute path to move destination dir
if (!fileMoveCheck.exists()) { //Check if file exists in move destination dir
filePath.moveTo(MOVETODIR); //If not exist then move
} else { //If exist must make new name and try again
var i = 0; //Counter for renaming
do {
i += 1;
fileMoveCheck = MOVETODIR + '\\' + fileName + " (" + i + ")" + "." + fileExtension; // Make new name look like: C:\\sherbee\\check\\123 (1).zip like Windows.
} while (fileMoveCheck.exists());
if (filePath.renameTo(fileMoveCheck)) { //Come here when file not exists and rename file
filePath.moveTo(MOVETODIR); //After rename move
} else {
//do nothing or abort maybe
}
});
I say silly because I don't know if I make paths correctly and what else is wrong.