filedir

Testseite

by Norbert Wilms

HTML

<!DOCTYPE html>
<html>
<body>

<h1>filedir testseite</h1>


<div id="filedir"></div>
<div id="test"></div>
<div id="test1"></div>

</body>
</html>

JavaScript

const dirs = [];
var mycnt = 0;
var link_dir_cl =
"https://www.iconarchive.com/download/i60226/zerode/plump/Folder.128.png";
var link_dir_op = "https://www.iconarchive.com/download/i60214/zerode/plump/Folder-My-documents.128.png";
var link_mp3file = "https://www.iconarchive.com/download/i60198/zerode/plump/Filetype-mp-3.128.png";
var link_play = "https://www.iconarchive.com/download/i7864/hopstarter/soft-scraps/Button-Play.128.png";
var link_empty = "https://www.iconarchive.com/download/i62706/ampeross/ampola/empty.128.png";


$(document).ready(function(){
  add_file("/dir1/file1");
  add_file("/dir1/file2");
  add_file("/dir2/file1");
  add_file("/dir2/file2");

});

function add_file(myfile) {
var dir;
var file;
var pos;
pos = 0;
//alert(filedir);
while ( myfile.indexOf("/",pos+1) > 0 ) {
  pos = myfile.indexOf("/",pos+1);
//  alert(pos);
}
dir = myfile.slice(0,pos+1);
file = myfile.slice(pos+1);
//alert("dir: "+dir+" File: "+file);
if ( dirs.includes(dir) ) {
  $("#filedir").append("<p>              File: "+file+"</p>");
} else {
  dirs.push(dir);
  $("#filedir").append("<div id='fd_paydir"+mycnt+"'>");
  $("#filedir").append("<img src='"+link_play+"' height=30px width=30px>");
  $("#filedir").append("</div>");
  $("#filedir").append("<img src='"+link_dir_cl+"' height=30px width=30px>"+dir.slice(1,dir.length-1));
  $("#fd_playdir"+mycnt).click(function() {
    alert("play dir "+dir);
  });
}
mycnt++;
$("#test").html(dirs);
document.getElementById("test1").innerHTML = dir.length;

}