getDir.js 642 B

12345678910111213141516171819202122232425262728
  1. /*
  2. getDir.js
  3. Author: tobychui
  4. An implementation in AGI script for getDir.php
  5. */
  6. function basename(filepath){
  7. return filepath.split("/").pop();
  8. }
  9. requirelib("filelib");
  10. var results = [];
  11. if (listpath == ""){
  12. listpath = "user:/";
  13. }
  14. if (listpath.substring(listpath.length - 1, listpath.length) != "/"){
  15. listpath = listpath + "/";
  16. }
  17. var fileList = filelib.aglob(listpath + "*");
  18. for (var i = 0; i < fileList.length; i++){
  19. if (filelib.isDir(fileList[i]) && basename(fileList[i]).substring(0, 1) != "."){
  20. results.push([fileList[i] + "/",basename(fileList[i])])
  21. }
  22. }
  23. sendJSONResp(JSON.stringify(results));