{"id":357,"date":"2017-12-29T04:50:54","date_gmt":"2017-12-29T04:50:54","guid":{"rendered":"http:\/\/govinddas.com\/?p=357"},"modified":"2017-12-29T04:50:54","modified_gmt":"2017-12-29T04:50:54","slug":"list-google-drive-folders-files-google-script","status":"publish","type":"post","link":"https:\/\/govinddas.com\/index.php\/list-google-drive-folders-files-google-script\/","title":{"rendered":"List of google drive folders\/files- google script"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><strong>List of my successful experiments in digital world :<\/strong><\/span><\/p>\n<p>Enlist names of google drive folder in spreadsheet<\/p>\n<p>Link code for google script :&nbsp;<a href=\"https:\/\/goo.gl\/qjMtj2\" target=\"_blank\" rel=\"noopener\">https:\/\/goo.gl\/qjMtj2<\/a><\/p>\n<p>Code is given below. (replace <span style=\"color: #ff0000;\">my drive<\/span> with name of your folder)<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/ replace your-folder below with the folder for which you want a listing<br \/>\nfunction listFolderContents() {<br \/>\nvar foldername = &#8216;<span style=\"color: #ff0000;\">my drive<\/span>&#8216;;<br \/>\nvar folderlisting = &#8216;listing of folder &#8216; + foldername;<\/p>\n<p>var folders = DriveApp.getFoldersByName(foldername)<br \/>\nvar folder = folders.next();<br \/>\nvar contents = folder.getFiles();<\/p>\n<p>var ss = SpreadsheetApp.create(folderlisting);<br \/>\nvar sheet = ss.getActiveSheet();<br \/>\nsheet.appendRow( [&#8216;name&#8217;, &#8216;link&#8217;] );<\/p>\n<p>var file;<br \/>\nvar name;<br \/>\nvar link;<br \/>\nvar row;<br \/>\nwhile(contents.hasNext()) {<br \/>\nfile = contents.next();<br \/>\nname = file.getName();<br \/>\nlink = file.getUrl();<br \/>\nsheet.appendRow( [name, link] );<br \/>\n}<br \/>\n};<\/p>\n<p>&nbsp;<\/p>\n<p>Place this script and allow google drive for permission. You will be able to save them in automatic spreadsheet in google drive parent folder. Example of my drive test (for files list) given below. You can replace circled areas according to your need- i.e. name of folder, and whether you need to enlist files names only or folder names only. (This script doesn&#8217;t work on hybrid, i.e. both file and folder names, so arrange them in drive accordingly. And ya, ignore cursor pipe sign preceding parenthesis.;-)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-345\" src=\"http:\/\/localhost\/wp-content\/uploads\/2017\/12\/google-script-to-get-list-of-files-or-folders-change-one-word-1-300x252.png\" alt=\"\" width=\"524\" height=\"440\" srcset=\"https:\/\/govinddas.com\/wp-content\/uploads\/2017\/12\/google-script-to-get-list-of-files-or-folders-change-one-word-1-300x252.png 300w, https:\/\/govinddas.com\/wp-content\/uploads\/2017\/12\/google-script-to-get-list-of-files-or-folders-change-one-word-1-322x270.png 322w, https:\/\/govinddas.com\/wp-content\/uploads\/2017\/12\/google-script-to-get-list-of-files-or-folders-change-one-word-1.png 716w\" sizes=\"auto, (max-width: 524px) 100vw, 524px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_357\" class=\"pvc_stats all  \" data-element-id=\"357\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/govinddas.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>List of my successful experiments in digital world : Enlist names of google drive folder in spreadsheet Link code for google script :&nbsp;https:\/\/goo.gl\/qjMtj2 Code is given below. (replace my drive with name of your folder) &nbsp; \/\/ replace your-folder below with the folder for which you want a listing function listFolderContents() { var foldername = &#8216;my drive&#8216;; var folderlisting = &#8216;listing of folder &#8216; + foldername; var folders = DriveApp.getFoldersByName(foldername) var folder = folders.next(); var contents = folder.getFiles(); var ss&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/govinddas.com\/index.php\/list-google-drive-folders-files-google-script\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_357\" class=\"pvc_stats all  \" data-element-id=\"357\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/govinddas.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":0,"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"wp:attachment":[{"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/govinddas.com\/index.php\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}