I have a situation where Event Script objects are vexing me. My aim is to reconcile the contents of downloaded Packages with what exists on disk after the files have been reviewed, and unwanted ones discarded, or others inserted by other Packages. I am aware of the 'filePath.exists()' method, but mgpai has suggested that 'filePath.getChildren()' method a better solution, in another situation in Post
https://board.jdownloader.org/showpo...postcount=1121
I have been trying to use this in my script snippet below, recognising that of the two, it's likely the much more economical with machine resources.
My plan is to loop through whichever of Link list and Disk File list is shorter and check if there's a match in the other list. I'm trying to use the Filesystem Path for the comparison. I believe that is what I've done in the snippet, as demonstrated by the log() responses shown, but the comparison always fails, with two slightly different variations below.
Is there a basic error or misunderstanding getting in my way?
If this is a deadend, I could compare the String representations of the filepath, or use 'filePath.exists()', which of these would be the more efficient?
I tried to use .constructor to throw some light on my comparisons, but that couldn't help. Why?
Code:
// Trigger: Downloadlist context menu button pressed
switch (name) {
case "LG context menu demo":
try {
// dlSelection appears to be the single item under the pointer, even if a range of lines is highlighted
var myDownloadlistSelection = dlSelection;
var myFilePackage = myDownloadlistSelection.getContextPackage();
// Get Links of Package in Downloads list
var myDownloadLinks = myFilePackage.getDownloadLinks();
// Get files actually existing in Package's disk Folder
var strDlFolder = myFilePackage.getDownloadFolder();
var folderFPath = getPath(strDlFolder); /*Get a FilePath Object*/
var filesPresent = folderFPath.getChildren();
// Get a sample Download Link and its matching File (indexes differ due to file deletions)
var sampleLink = myDownloadLinks[14];
var sampleLinkFPath = getPath(sampleLink.getDownloadPath());
var sampleFile = filesPresent[1];
log(folderFPath);
// -> /Volumes/Data1/JD/Test
log(sampleLink);
// -> DownloadLink Instance: 18.jpg
log(typeof(sampleLink));
// -> object
log(sampleLink.constructor);
// -> undefined
log(sampleFile);
// -> /Volumes/Data1/JD/Test/18.jpg
log(typeof(sampleFile));
// -> object
log(sampleFile.constructor);
// -> undefined
log(sampleLink == sampleFile);
// -> false <-- ?
log(sampleLinkFPath);
// -> /Volumes/Data1/JD/Test/18.jpg
log(typeof(sampleLinkFPath));
// -> object
log(sampleLinkFPath.constructor);
// -> undefined
log(sampleLinkFPath == sampleFile);
// -> false <-- ?
} catch (e) {
alert(e.message);
}
break;
default:
}