Skip to content

Instantly share code, notes, and snippets.

@naosim
Created March 17, 2023 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naosim/864c5abe8f3bfddda25fb7da51b00701 to your computer and use it in GitHub Desktop.
Save naosim/864c5abe8f3bfddda25fb7da51b00701 to your computer and use it in GitHub Desktop.
GASでファイルIDをパスに変換する
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