{"id":295,"date":"2025-05-26T13:54:39","date_gmt":"2025-05-26T04:54:39","guid":{"rendered":"https:\/\/cg-method.com\/google\/?p=295"},"modified":"2025-05-26T13:54:39","modified_gmt":"2025-05-26T04:54:39","slug":"google-drive-folder-file-count-gas","status":"publish","type":"post","link":"https:\/\/cg-method.com\/google\/google-drive-folder-file-count-gas\/","title":{"rendered":"Google\u30c9\u30e9\u30a4\u30d6\u2502\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3092\u96c6\u8a08\u3059\u308b\u65b9\u6cd5\u2502GAS"},"content":{"rendered":"\n<p>\u30ea\u30e2\u30fc\u30c8\u30ef\u30fc\u30af\u304c\u65e5\u5e38\u306b\u306a\u308a\u3001<strong>Google\u30c9\u30e9\u30a4\u30d6\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u5171\u6709\u3084\u7ba1\u7406\u306e\u6a5f\u4f1a\u304c\u6025\u5897<\/strong>\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3057\u304b\u3057\u3001Google\u30c9\u30e9\u30a4\u30d6\u3067\u306f<strong>\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u4f55\u30d5\u30a1\u30a4\u30eb\u3042\u308b\u304b<\/strong>\u306f\u6a19\u6e96UI\u3067\u306f\u8868\u793a\u3055\u308c\u307e\u305b\u3093<\/p>\n\n\n\n<p>\u300c\u3069\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u3069\u308c\u3060\u3051\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u304b\uff1f\u300d<\/p>\n\n\n\n<p>\u300c\u6574\u7406\u3055\u308c\u3066\u3044\u308b\u304b\u628a\u63e1\u3057\u305f\u3044\u300d<\/p>\n\n\n\n<p>\u305d\u3093\u306a\u5834\u9762\u3067\u4fbf\u5229\u306a\u306e\u304c\u3001<strong>Google Apps Script\uff08GAS\uff09<\/strong>\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001GAS\u3092\u4f7f\u3063\u3066\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3092\u8abf\u3079\u308b2\u3064\u306e\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> \u65b9\u6cd51\uff1a1\u30d5\u30a9\u30eb\u30c0\u76f4\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3060\u3051\u30ab\u30a6\u30f3\u30c8\u3059\u308b<\/h2>\n\n\n\n<p>\u6700\u3082\u30b7\u30f3\u30d7\u30eb\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u3053\u3061\u3089\u3002\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0\u76f4\u4e0b\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u6570\u306e\u307f\u3092\u30ab\u30a6\u30f3\u30c8\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong>Google Apps Script\uff08GAS\uff09<\/strong><\/p>\n\n\n<div class=\"swell-block-postLink\">\t\t\t<a href=\"https:\/\/script.google.com\/home\/projects\/create\" class=\"c-blogLink -external\" data-style=\"text\" target=\"_blank\" rel=\"noopener noreferrer\">\n\t\t\t\t<!-- <i class=\"c-blogLink__icon icon-link\" role=\"presentation\"><\/i> -->\n\t\t\t\t<span class=\"c-blogLink__icon\">\n\t\t\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"swl-svg-externalLink __svg\" width=\"1em\" height=\"1em\" viewBox=\"0 0 48 48\" role=\"img\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M44 2H30c-1.1 0-2 .9-2 2s.9 2 2 2h9.2L24 21.2c-.8.8-.8 2 0 2.8s2 .8 2.8 0L42 8.8V18c0 1.1.9 2 2 2s2-.9 2-2V4c0-1.1-.9-2-2-2z\" \/><path d=\"M41 27c-1.1 0-2 .9-2 2v10c0 1.1-.9 2-2 2H9c-1.1 0-2-.9-2-2V11c0-1.1.9-2 2-2h10c1.1 0 2-.9 2-2s-.9-2-2-2H9c-3.3 0-6 2.7-6 6v28c0 3.3 2.7 6 6 6h28c3.3 0 6-2.7 6-6V29c0-1.1-.9-2-2-2z\" \/><\/svg>\t\t\t\t<\/span>\n\t\t\t\t<span class=\"c-blogLink__text\">Apps Script \u00a0|\u00a0 Google for Developers<\/span>\n\t\t\t<\/a>\n\t\t<\/div>\n\n\n<h3 class=\"wp-block-heading\">\u30b3\u30fc\u30c9\uff1a<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function myFunction() {\n  var folder = DriveApp.getFolderById(&quot;\u30d5\u30a9\u30eb\u30c0ID&quot;); \/\/ \u5bfe\u8c61\u30d5\u30a9\u30eb\u30c0\u306eID\n  var contents = folder.getFiles();\n  var i = 0;\n  while(contents.hasNext()) {\n    contents.next();\n    i++;\n  }\n  Logger.log(&quot;\u3053\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u306f &quot; + i + &quot; \u3067\u3059\u3002&quot;);\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u30d5\u30a9\u30eb\u30c0ID\u306fURL\u304b\u3089\u53d6\u5f97\u53ef\u80fd\uff1a<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>https:\/\/drive.google.com\/drive\/folders\/\u3053\u3053\u304c\u30d5\u30a9\u30eb\u30c0ID<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-style-border\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"537\" src=\"https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h27_40-768x537-1.jpg\" alt=\"\" class=\"wp-image-297\" srcset=\"https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h27_40-768x537-1.jpg 768w, https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h27_40-768x537-1-300x210.jpg 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u65b9\u6cd52\uff1a\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u3092\u542b\u3081\u3066\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3092\u96c6\u8a08<\/h2>\n\n\n\n<p>\u3055\u3089\u306b\u5b9f\u8df5\u7684\u306a\u306e\u304c\u3053\u3061\u3089\u306e\u65b9\u6cd5\u3002<strong>\u89aa\u30d5\u30a9\u30eb\u30c0\u914d\u4e0b\u306e\u3059\u3079\u3066\u306e\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u3092\u518d\u5e30\u7684\u306b\u63a2\u7d22\u3057\u3001\u30d5\u30a1\u30a4\u30eb\u6570\u3092\u30ab\u30a6\u30f3\u30c8<\/strong>\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u624b\u9806\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u65b0\u3057\u3044\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3092\u4f5c\u6210<\/strong><\/li>\n\n\n\n<li>\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u300c\u30c4\u30fc\u30eb &gt; \u30b9\u30af\u30ea\u30d7\u30c8\u30a8\u30c7\u30a3\u30bf\u300d\u3092\u958b\u304f<\/li>\n\n\n\n<li>\u4ee5\u4e0b\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8cbc\u308a\u4ed8\u3051\u3001\u5b9f\u884c<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u30b3\u30fc\u30c9\uff1a<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>function myFunction() {\n  var objSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();\n  objSpreadsheet.insertSheet(&quot;\u30d5\u30a1\u30a4\u30eb\u6570&quot;, 0);\n  var sheet = objSpreadsheet.getSheets()[0];\n  var key = &quot;\u89aa\u30d5\u30a9\u30eb\u30c0\u306eID&quot;; \/\/ \u30d5\u30a9\u30eb\u30c0ID\u3092\u6307\u5b9a\n  var rootFolder = DriveApp.getFolderById(key);\n  var folderlist = [[rootFolder.getName(), key]];\n\n  \/\/ \u518d\u5e30\u7684\u306b\u30d5\u30a9\u30eb\u30c0\u3092\u5c55\u958b\n  for (var i = 0; i &lt; folderlist.length; i++) {\n    var subFolders = DriveApp.getFolderById(folderlist[i][1]).getFolders();\n    while (subFolders.hasNext()) {\n      var folder = subFolders.next();\n      folderlist.push([folderlist[i][0] + &quot; &gt; &quot; + folder.getName(), folder.getId()]);\n    }\n  }\n\n  \/\/ \u30d8\u30c3\u30c0\u30fc\n  sheet.clear();\n  sheet.getRange(1, 1).setValue(&quot;\u30d5\u30a9\u30eb\u30c0\u540d&quot;);\n  sheet.getRange(1, 2).setValue(&quot;\u30d5\u30a1\u30a4\u30eb\u6570&quot;);\n\n  \/\/ \u30d5\u30a1\u30a4\u30eb\u6570\u3092\u30ab\u30a6\u30f3\u30c8\n  for (var j = 0; j &lt; folderlist.length; j++) {\n    var folder = DriveApp.getFolderById(folderlist[j][1]);\n    var files = folder.getFiles();\n    var count = 0;\n    while (files.hasNext()) {\n      files.next();\n      count++;\n    }\n    sheet.getRange(j + 2, 1).setValue(folderlist[j][0]);\n    sheet.getRange(j + 2, 2).setValue(count);\n  }\n}\n<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-style-border\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"977\" src=\"https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h53_10-1.jpg\" alt=\"\" class=\"wp-image-298\" srcset=\"https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h53_10-1.jpg 744w, https:\/\/cg-method.com\/google\/wp-content\/uploads\/2025\/05\/2020-08-04_12h53_10-1-228x300.jpg 228w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9f\u884c\u5f8c\u306e\u7d50\u679c<\/h3>\n\n\n\n<p>\u30b9\u30af\u30ea\u30d7\u30c8\u5b9f\u884c\u5f8c\u3001\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u306b\u300c\u30d5\u30a1\u30a4\u30eb\u6570\u300d\u3068\u3044\u3046\u540d\u524d\u306e\u30b7\u30fc\u30c8\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4e2d\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<strong>\u30d5\u30a9\u30eb\u30c0\u968e\u5c64\u3068\u305d\u308c\u305e\u308c\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u304c\u4e00\u89a7\u8868\u793a<\/strong>\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u30d5\u30a9\u30eb\u30c0\u540d<\/th><th>\u30d5\u30a1\u30a4\u30eb\u6570<\/th><\/tr><\/thead><tbody><tr><td>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u8cc7\u6599<\/td><td>12<\/td><\/tr><tr><td>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u8cc7\u6599 &gt; \u8b70\u4e8b\u9332<\/td><td>7<\/td><\/tr><tr><td>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u8cc7\u6599 &gt; \u5951\u7d04\u66f8<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9f\u969b\u306b\u4f7f\u3063\u3066\u307f\u305f\u611f\u60f3<\/h3>\n\n\n\n<p>\u8a66\u3057\u306b\u81ea\u5206\u306e\u300cOLD\u300d\u30d5\u30a9\u30eb\u30c0\u3067\u8a66\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u3001<strong>\u7d042,800\u500b\u3082\u306e\u30d5\u30a1\u30a4\u30eb<\/strong>\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u5224\u660e\u3002<\/p>\n\n\n\n<p>Google\u30c9\u30e9\u30a4\u30d6\u3067\u306f<strong>\u8996\u899a\u7684\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u30d5\u30a1\u30a4\u30eb\u306e\u84c4\u7a4d<\/strong>\u3082\u3001GAS\u3092\u4f7f\u3048\u3070\u53ef\u8996\u5316\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u65b9\u6cd5<\/th><th>\u5185\u5bb9<\/th><th>\u7279\u5fb4<\/th><\/tr><\/thead><tbody><tr><td>\u65b9\u6cd51<\/td><td><code>DriveApp.getFiles()<\/code><\/td><td>\u5358\u4e00\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3060\u3051\u78ba\u8a8d<\/td><\/tr><tr><td>\u65b9\u6cd52<\/td><td>\u518d\u5e30\u7684\u306b\u30d5\u30a9\u30eb\u30c0\u63a2\u7d22<\/td><td>\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u3092\u542b\u3081\u305f\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u6570\u3092\u78ba\u8a8d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Google\u30c9\u30e9\u30a4\u30d6\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u5897\u3048\u3066\u304d\u305f\u3068\u611f\u3058\u305f\u3089\u3001\u307e\u305a\u306f<strong>\u53ef\u8996\u5316\u3059\u308b\u3053\u3068\u304c\u7b2c\u4e00\u6b69<\/strong>\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u00d7GAS\u3067\u3001<strong>\u8ab0\u3067\u3082\u7121\u6599\u3067\u30c9\u30e9\u30a4\u30d6\u7ba1\u7406\u306e\u898b\u3048\u308b\u5316<\/strong>\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>\u30ea\u30e2\u30fc\u30c8\u30ef\u30fc\u30af\u304c\u65e5\u5e38\u306b\u306a\u308a\u3001Google\u30c9\u30e9\u30a4\u30d6\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u5171\u6709\u3084\u7ba1\u7406\u306e\u6a5f\u4f1a\u304c\u6025\u5897\u3057\u307e\u3057\u305f\u3002 \u3057\u304b\u3057\u3001Google\u30c9\u30e9\u30a4\u30d6\u3067\u306f\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u4f55\u30d5\u30a1\u30a4\u30eb\u3042\u308b\u304b\u306f\u6a19\u6e96UI\u3067\u306f\u8868\u793a\u3055\u308c\u307e\u305b\u3093 \u300c\u3069\u306e\u30d5\u30a9\u30eb\u30c0\u306b\u3069\u308c\u3060\u3051\u30c7\u30fc\u30bf\u304c\u5165\u3063 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":299,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[18,9],"class_list":["post-295","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google-drive","tag-gas","tag-free"],"_links":{"self":[{"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":2,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/posts\/295\/revisions\/300"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/media\/299"}],"wp:attachment":[{"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cg-method.com\/google\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}