2 replies

Can you please post an example of how you're calling the function?

ZC

Tasker can access folders normally,but javascript function listFiles() always return undefine.
Tasker veersion : 5.9.3
Android version : 8.0.0 EMUI 8.0.0
Device : Huawei Honor 7C

in old tasker version,listFiles() can return files array object.

my javascript code:

var _bing_base_url_ = "http://www.bing.com/";
var _save_path_ = "/sdcard/BingWallpaper/";


var imgFiles = listFiles( _save_path_ );
var imgFilesArr = imgFiles.split( '\n' );

var wallPaperFile = "";

function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 
}

try {
  var wallPaperFile1 = imgFilesArr[getRandomIntInclusive(0,imgFilesArr.length-1)];
  var wallPaperFile2 = imgFilesArr[getRandomIntInclusive(0,imgFilesArr.length-1)];
  var wallPaperFile_new = imgFilesArr[imgFilesArr.length-1];
  
  var wallPaperFilesArr = [wallPaperFile1,wallPaperFile2,wallPaperFile_new];
  
  wallPaperFile = wallPaperFilesArr[getRandomIntInclusive(0,wallPaperFilesArr.length-1)];
} catch(e) {
  flash('there was an error: ' + e.message);
}

tk.setGlobal("Bingfiles",wallPaperFile);
tk.setGlobal("Bingpaperinfo",wallPaperFile.replace(new RegExp(_save_path_,"gm"),"").replace(new RegExp(".jpg","gm"),""));

Hi. It still works for me. The path should not contain the "/sdcard/" part. For example, I just tried it with the Download folder on the root of my internal storage and simply set the path as "Download" and it works. Can you try that please?