Nugroho's blog.: List Files on Certain Google Drive Folder and It's Subfolders

Saturday, November 7, 2015

List Files on Certain Google Drive Folder and It's Subfolders

 ...and display it in html format using div tag with border so the files in subfolders will displayed in box, and files in other subfolder will displayed in other box. If subfolder have subfolder, then files inside that sub-subfolder will displayed inside box inside box, :s :P :D

 The Algorithm itself is bit like this previous post. OK, I copy and paste a little bit of,..., ok most of code from it.

 All by Google App Script.

 I use string variable named text to receive all output.

 Basically, after the script is completely executed, the content of variable text  is complete html source code.


 Here it is

function listFilesNFolders(form) { 
var text = '';
var lv = 2; //for level depth
var home = DriveApp.getFolderById('0BxZS62a5NdNYUGxySmp2QW41OUU');
var NIM = home.getFoldersByName("aa");
var NIMfold =;
text = crawl(NIMfold,text,lv);
} else{
text+='<br> Anda belum mengupload tugas';
return text;

function crawl(home,text,lv){
var files=home.getFiles();
text+='<div id="p'+lv+'"style="border: 1px solid black;">';
while (files.hasNext()){
var folders=home.getFolders();
while (folders.hasNext()){
text+='<br><div id="p'+lv+'"style="border: 1px solid black;">';
text = crawl(folder,text,lv);
text+='<br>'; text+='</div>';
return text;
} function
doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');


<!DOCTYPE html>
<base target="_top">
input { display:block; margin: 20px; }

#p1 { position: relative; left: 10px;}
#p2 { position: relative; left: 20px;}
#p3 { position: relative; left: 30px;}
#p4 { position: relative; left: 40px;}
#p5 { position: relative; left: 50px;}
#p6 { position: relative; left: 60px;}

h1 { position: relative;margin-left: 10px;font-weight: bold;}
h2 { position: relative;margin-left: 20px;font-weight: bold;}
h3 { position: relative;margin-left: 30px;font-weight: bold;}
h4 { position: relative;margin-left: 40px;font-weight: bold;}
h5 { position: relative;margin-left: 50px;font-weight: bold;}
h6 { position: relative;margin-left: 60px;font-weight: bold;}


<form id="myForm">
<input type="submit"
return false;


<div id="output"></div>

function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;


Look at the HTML code, the key for indentation is <px> tag with x = 1,2,3,4,5,6. The bigger the number, the more left margin increased. I modify the <hx> tag too.

The content of text variable after script's completely executed.

<br><h2>Testing</h2><br><h2>aa</h2><div id="p3"style="border: 1px solid black;"><br>nug.f<br>nug.f<br>nug.f<br><br>nug.f<br>nug.f<br>nug.f<br>nug.f<br>nug.f<br>nug.f<br>nug.f<br>F-1.xls</div><br><br><div id="p3"style="border: 1px solid black;"><br><h3>Desktop</h3><div id="p4"style="border: 1px solid black;"><br>.DS_Store<br>tiketpulang.pdf<br>tiketberangkat.pdf<br>Gmail - Bukti Pemesanan Internet PT. KAI Persero.pdf<br>Gmail - Bukti Pemesanan Internet PT. KAI Persero (pulang).pdf</div><br><br><div id="p4"style="border: 1px solid black;"><br><h4>freebsdvbox</h4><div id="p5"style="border: 1px solid black;"><br>Screen Shot 2015-01-01 at 7.20.02 PM.png<br>Screen Shot 2015-01-01 at 1.56.36 PM.png<br>Screen Shot 2015-01-01 at 1.36.32 PM.png<br>Screen Shot 2015-01-01 at 1.36.00 PM.png<br>Screen Shot 2015-01-01 at 1.35.46 PM.png<br>Screen Shot 2015-01-01 at 1.33.32 PM.png<br>Screen Shot 2015-01-01 at 1.32.53 PM.png<br>Screen Shot 2014-12-31 at 11.30.41 PM.png<br>Screen Shot 2014-12-31 at 11.30.38 PM.png<br>Screen Shot 2014-12-31 at 11.30.16 PM.png<br>Screen Shot 2014-12-31 at 11.30.03 PM.png<br>Screen Shot 2014-12-31 at 11.29.13 PM.png<br>Screen Shot 2014-12-31 at 11.28.00 PM.png<br>Screen Shot 2014-12-31 at 11.26.33 PM.png<br>Screen Shot 2014-12-31 at 11.26.18 PM.png<br>Screen Shot 2014-12-30 at 8.16.46 AM.png<br>.DS_Store</div><br><br><div id="p5"style="border: 1px solid black;"><br><h5>freebsdss</h5><div id="p6"style="border: 1px solid black;"><br>.DS_Store</div><br><br></div><br></div><br></div><br><div id="p3"style="border: 1px solid black;"><br><h3>freebsdvbox</h3><div id="p4"style="border: 1px solid black;"></div><br><br><div id="p4"style="border: 1px solid black;"><br><h4>freebsdss</h4><div id="p5"style="border: 1px solid black;"></div><br><br></div><br></div><br><div id="p3"style="border: 1px solid black;"><br><h3>tugas momentum</h3><div id="p4"style="border: 1px solid black;"><br><br><br><br>Screen Shot 2015-10-05 at 6.57.37 AM.png<br>IMG-20151004-WA0091.jpg<br><br>20151004_201055.jpg<br>.DS_Store</div><br><br><div id="p4"style="border: 1px solid black;"><br><h4>attachments</h4><div id="p5"style="border: 1px solid black;"><br>20151004_221456.jpg<br>20151004_221113.jpg<br>20151004_221052.jpg<br>20151004_221024.jpg</div><br><br></div><br><div id="p4"style="border: 1px solid black;"><br><h4>tugasfisikarevisiyangsalah</h4><div id="p5"style="border: 1px solid black;"><br>IMG_1494.JPG<br>IMG_1489.JPG<br>IMG-20151005-WA0012.jpg</div><br><br></div><br><div id="p4"style="border: 1px solid black;"><br><h4>tugastumbukan</h4><div id="p5"style="border: 1px solid black;"><br>IMG-20151004-WA0039.jpg<br>IMG-20151004-WA0038.jpg<br>IMG-20151004-WA0037.jpg</div><br><br></div><br><div id="p4"style="border: 1px solid black;"><br><h4>tugasmomentum</h4><div id="p5"style="border: 1px solid black;"><br>IMG_20151004_143049.jpg<br>IMG_20151004_143023.jpg</div><br><br></div><br></div><br><div id="p3"style="border: 1px solid black;"><br><h3>pyTest</h3><div id="p4"style="border: 1px solid black;"><br><br><br><br><br><br><br>nummpyArray.pdf<br><br>nugroho.f90<br>nugroho.f<br><br>nug.f<br><br>lines.mp4<br><br>im.mp4<br><br>hellofortran.f<br>Fortran-and-CModulePython.pdf<br><br><br><br><br><br><br><br><br><br><br><br><br><br>.DS_Store</div><br><br><div id="p4"style="border: 1px solid black;"><br><h4>air</h4><div id="p5"style="border: 1px solid black;"><br>air700.mp4<br>air4098f1024bit20int.mp4<br>air4096f1024bit.mp4<br>air2700f512bit.mp4<br>air1700.mp4</div><br><br></div><br></div>

 Yeah, it looks like garbage, but it's actual html code and if we open it in web browser, it will looks like this.

No comments:

323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)