Created
March 17, 2023 13:10
-
-
Save naosim/864c5abe8f3bfddda25fb7da51b00701 to your computer and use it in GitHub Desktop.
GASでファイルIDをパスに変換する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFilePathListById(fileId) { | |
var file = DriveApp.getFileById(fileId); | |
return getParentPathList(file).map(v => 'G:\\' + v + '\\' + file.getName()); | |
} | |
function iteratorToArray(iterator) { | |
var result = []; | |
while (iterator.hasNext()) { | |
result.push(iterator.next()); | |
} | |
return result; | |
} | |
function getParentPathList(file) { | |
var result = []; | |
iteratorToArray(file.getParents()).forEach(p => { | |
var parentList = getParentPathList(p) | |
if(parentList.length == 0) { | |
result.push(p.getName()) | |
} else { | |
parentList.forEach(p2 => { | |
result.push(p2 + '\\' + p.getName()) | |
}); | |
} | |
}) | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment