스크립트가 Google Drive의 파일 및 폴더를 생성, 검색, 수정하도록 허용합니다. 공유 드라이브의 파일 또는 폴더에 액세스하려면 고급 Drive 서비스를 사용하세요.
// Logs the name of every file in the user's Drive. var files = DriveApp.getFiles(); while (files.hasNext()) { var file = files.next(); console.log(file.getName()); }
속성
속성 | 유형 | 설명 |
---|---|---|
Access | Access | 명시적으로 액세스 권한이 부여된 개별 사용자 외에 파일이나 폴더에 액세스할 수 있는 사용자 클래스를 나타내는 enum입니다. |
Permission | Permission | 명시적으로 액세스 권한이 부여된 개별 사용자 외에 파일이나 폴더에 액세스할 수 있는 사용자에게 부여된 권한을 나타내는 열거형입니다. |
방법
메서드 | 반환 유형 | 간략한 설명 |
---|---|---|
continueFileIterator(continuationToken) | FileIterator | 이전 반복자의 연속 토큰을 사용하여 파일 반복을 재개합니다. |
continueFolderIterator(continuationToken) | FolderIterator | 이전 반복자의 연속 토큰을 사용하여 폴더 반복을 재개합니다. |
createFile(blob) | File | 지정된 임의의 데이터 Blob 를 사용하여 사용자 Drive 루트에 파일을 만듭니다. |
createFile(name, content) | File | 지정된 이름과 콘텐츠로 사용자 Drive의 루트에 텍스트 파일을 만듭니다. |
createFile(name, content, mimeType) | File | 사용자 드라이브의 루트에 지정된 이름, 콘텐츠, MIME 유형으로 파일을 만듭니다. |
createFolder(name) | Folder | 사용자 Drive의 루트에 지정된 이름으로 폴더를 만듭니다. |
createShortcut(targetId) | File | 제공된 Drive 항목 ID의 바로가기를 만들어 반환합니다. |
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey) | File | 제공된 Drive 항목 ID 및 리소스 키의 바로가기를 만들어 반환합니다. |
enforceSingleParent(value) | void | 항목 상위 요소에 영향을 미치는 모든 호출에 대해 forceSingleParent 동작을 사용 설정하거나 중지합니다. |
getFileById(id) | File | 지정된 ID가 있는 파일을 가져옵니다. |
getFileByIdAndResourceKey(id, resourceKey) | File | 지정된 ID와 리소스 키가 있는 파일을 가져옵니다. |
getFiles() | FileIterator | 사용자 드라이브에 있는 모든 파일의 컬렉션을 가져옵니다. |
getFilesByName(name) | FileIterator | 사용자의 Drive에서 지정된 이름을 가진 모든 파일의 컬렉션을 가져옵니다. |
getFilesByType(mimeType) | FileIterator | 사용자의 Drive에서 지정된 MIME 유형을 가진 모든 파일의 컬렉션을 가져옵니다. |
getFolderById(id) | Folder | 지정된 ID가 있는 폴더를 가져옵니다. |
getFolderByIdAndResourceKey(id, resourceKey) | Folder | 지정된 ID와 리소스 키가 있는 폴더를 가져옵니다. |
getFolders() | FolderIterator | 사용자 드라이브에 있는 모든 폴더의 컬렉션을 가져옵니다. |
getFoldersByName(name) | FolderIterator | 사용자 Drive에서 특정 이름을 가진 모든 폴더의 컬렉션을 가져옵니다. |
getRootFolder() | Folder | 사용자 Drive의 루트에 있는 폴더를 가져옵니다. |
getStorageLimit() | Integer | 사용자가 Drive에 저장할 수 있는 바이트 수를 가져옵니다. |
getStorageUsed() | Integer | 사용자가 현재 Drive에 저장하고 있는 바이트 수를 가져옵니다. |
getTrashedFiles() | FileIterator | 사용자 Drive의 휴지통에 있는 모든 파일의 컬렉션을 가져옵니다. |
getTrashedFolders() | FolderIterator | 사용자 Drive의 휴지통에 있는 모든 폴더의 컬렉션을 가져옵니다. |
searchFiles(params) | FileIterator | 사용자의 드라이브에서 지정된 검색 기준과 일치하는 모든 파일의 컬렉션을 가져옵니다. |
searchFolders(params) | FolderIterator | 사용자의 드라이브에서 지정된 검색 기준과 일치하는 모든 폴더의 컬렉션을 가져옵니다. |
자세한 문서
continueFileIterator(continuationToken)
이전 반복자의 연속 토큰을 사용하여 파일 반복을 재개합니다. 이 메서드는 한 실행에서 반복자를 처리할 때 최대 실행 시간을 초과하는 경우에 유용합니다. 연속 토큰은 일반적으로 1주일 동안 유효합니다.
// Continues getting a list of all 'Untitled document' files in the user's Drive. // Creates a file iterator named 'previousIterator'. const previousIterator = DriveApp.getFilesByName('Untitled document'); // Gets continuation token from the previous file iterator. const continuationToken = previousIterator.getContinuationToken(); // Creates a new iterator using the continuation token from the previous file iterator. const newIterator = DriveApp.continueFileIterator(continuationToken); // Resumes the file iteration using a continuation token from 'firstIterator' and // logs the file name. if (newIterator.hasNext()) { const file = newIterator.next(); console.log(file.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
continuationToken | String | 이전 파일 반복자의 연속 토큰입니다. |
리턴
FileIterator
- 연속 토큰이 생성되었을 때 이전 반복자에 남아 있었던 파일 모음입니다.
continueFolderIterator(continuationToken)
이전 반복자의 연속 토큰을 사용하여 폴더 반복을 재개합니다. 이 메서드는 한 실행에서 반복자를 처리할 때 최대 실행 시간을 초과하는 경우에 유용합니다. 연속 토큰은 일반적으로 1주일 동안 유효합니다.
// Continues getting a list of all folders in user's Drive. // Creates a folder iterator named 'previousIterator'. const previousIterator = DriveApp.getFolders(); // Gets continuation token from the previous folder iterator. const continuationToken = previousIterator.getContinuationToken(); // Creates a new iterator using the continuation token from the previous folder iterator. const newIterator = DriveApp.continueFolderIterator(continuationToken); // Resumes the folder iteration using a continuation token from the previous iterator and logs // the folder name. if (newIterator.hasNext()) { const folder = newIterator.next(); console.log(folder.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
continuationToken | String | 이전 폴더 반복자의 연속 토큰입니다. |
리턴
FolderIterator
- 연속 토큰이 생성되었을 때 이전 반복자에 남아 있었던 폴더 모음입니다.
createFile(blob)
지정된 임의의 데이터 Blob
를 사용하여 사용자 Drive 루트에 파일을 만듭니다.
// Create an image file in Google Drive using the Maps service. var blob = Maps.newStaticMap().setCenter('76 9th Avenue, New York NY').getBlob(); DriveApp.createFile(blob);
매개변수
이름 | 유형 | 설명 |
---|---|---|
blob | BlobSource | 새 파일의 데이터입니다. |
리턴
File
- 새 파일입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
createFile(name, content)
지정된 이름과 콘텐츠로 사용자 Drive의 루트에 텍스트 파일을 만듭니다. content
가 50MB보다 크면 예외가 발생합니다.
// Create a text file with the content "Hello, world!" DriveApp.createFile('New Text File', 'Hello, world!');
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 새 파일의 이름입니다. |
content | String | 새 파일의 콘텐츠입니다. |
리턴
File
- 새 파일입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
createFile(name, content, mimeType)
사용자 드라이브의 루트에 지정된 이름, 콘텐츠, MIME 유형으로 파일을 만듭니다. content
가 10MB보다 크면 예외가 발생합니다.
// Create an HTML file with the content "Hello, world!" DriveApp.createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 새 파일의 이름입니다. |
content | String | 새 파일의 콘텐츠입니다. |
mimeType | String | 새 파일의 MIME 유형입니다. |
리턴
File
- 새 파일입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
createFolder(name)
createShortcut(targetId)
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)
제공된 Drive 항목 ID 및 리소스 키의 바로가기를 만들어 반환합니다. 리소스 키는 링크를 사용하여 공유된 타겟 파일 또는 폴더에 액세스하기 위해 전달해야 하는 추가 매개변수입니다.
// Creates shortcuts for all folders in the user's drive that have a specific name. // TODO(developer): Replace 'Test-Folder' with a valid folder name in your drive. const folders = DriveApp.getFoldersByName('Test-Folder'); // Iterates through all folders named 'Test-Folder'. while (folders.hasNext()) { const folder = folders.next(); // Creates a shortcut to the provided Drive item ID and resource key, and returns it. DriveApp.createShortcutForTargetIdAndResourceKey(folder.getId(), folder.getResourceKey()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
targetId | String | 대상 파일 또는 폴더의 ID입니다. |
targetResourceKey | String | 대상 파일 또는 폴더의 리소스 키 |
리턴
File
- 새 단축키입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
enforceSingleParent(value)
항목 상위 요소에 영향을 미치는 모든 호출에 대해 forceSingleParent 동작을 사용 설정하거나 중지합니다.
자세한 내용은 Google Drive의 폴더 구조 및 공유 모델 간소화 블로그를 참고하세요.
// Enables enforceSingleParent behavior for all calls affecting item parents. DriveApp.enforceSingleParent(true);
매개변수
이름 | 유형 | 설명 |
---|---|---|
value | Boolean | forceSingleParent 플래그의 새로운 상태입니다. |
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
getFileById(id)
지정된 ID가 있는 파일을 가져옵니다. 파일이 없거나 사용자에게 파일에 액세스할 수 있는 권한이 없는 경우 스크립팅 예외가 발생합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace 'Test' with your file name. const files = DriveApp.getFilesByName('Test'); if (files.hasNext()) { // Gets the ID of each file in the list. const fileId = files.next().getId(); // Gets the file name using its ID and logs it to the console. console.log(DriveApp.getFileById(fileId).getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 파일의 ID입니다. |
리턴
File
- 지정된 ID의 파일입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFileByIdAndResourceKey(id, resourceKey)
지정된 ID와 리소스 키가 있는 파일을 가져옵니다. 리소스 키는 링크를 사용하여 공유된 파일에 액세스하기 위해 전달해야 하는 추가 매개변수입니다.
파일이 존재하지 않거나 사용자에게 파일 액세스 권한이 없는 경우 스크립팅 예외가 발생합니다.
// Gets a list of all files in Drive with the given name. // TODO(developer): Replace 'Test' with your file name. const files = DriveApp.getFilesByName('Test'); if (files.hasNext()) { // Gets the first file in the list. const file = files.next(); // Gets the ID and resource key. const key = file.getResourceKey(); const id = file.getId(); // Logs the file name to the console using its ID and resource key. console.log(DriveApp.getFileByIdAndResourceKey(id, key).getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 파일의 ID입니다. |
resourceKey | String | 폴더의 리소스 키입니다. |
리턴
File
- 지정된 ID의 파일입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFiles()
사용자 드라이브에 있는 모든 파일의 컬렉션을 가져옵니다.
리턴
FileIterator
- 사용자 드라이브에 있는 모든 파일 모음입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFilesByName(name)
사용자의 Drive에서 지정된 이름을 가진 모든 파일의 컬렉션을 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 찾을 파일의 이름입니다. |
리턴
FileIterator
- 사용자 드라이브에 있는 특정 이름을 가진 모든 파일 컬렉션입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFilesByType(mimeType)
사용자의 Drive에서 지정된 MIME 유형을 가진 모든 파일의 컬렉션을 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
mimeType | String | 찾을 파일의 MIME 유형입니다. |
리턴
FileIterator
- 사용자 드라이브에 있으며 지정된 MIME 유형을 가진 모든 파일의 모음입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFolderById(id)
getFolderByIdAndResourceKey(id, resourceKey)
지정된 ID와 리소스 키가 있는 폴더를 가져옵니다. 리소스 키는 링크를 사용하여 공유된 폴더에 액세스하기 위해 전달해야 하는 추가 매개변수입니다.
폴더가 존재하지 않거나 사용자에게 폴더에 액세스할 수 있는 권한이 없으면 스크립팅 예외가 발생합니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
id | String | 폴더의 ID입니다. |
resourceKey | String | 폴더의 리소스 키입니다. |
리턴
Folder
- 지정된 ID가 있는 폴더입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFolders()
사용자 드라이브에 있는 모든 폴더의 컬렉션을 가져옵니다.
리턴
FolderIterator
- 사용자 드라이브에 있는 모든 폴더 컬렉션입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFoldersByName(name)
사용자 Drive에서 특정 이름을 가진 모든 폴더의 컬렉션을 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 찾을 폴더의 이름입니다. |
리턴
FolderIterator
- 사용자 드라이브에 있는 특정 이름의 모든 폴더 컬렉션입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getRootFolder()
사용자 Drive의 루트에 있는 폴더를 가져옵니다.
// Gets the user's My Drive folder and logs its name to the console. console.log(DriveApp.getRootFolder().getName()); // Logs the Drive owner's name to the console. console.log(DriveApp.getRootFolder().getOwner().getName());
리턴
Folder
- 사용자 드라이브의 루트 폴더입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getStorageLimit()
사용자가 Drive에 저장할 수 있는 바이트 수를 가져옵니다.
// Gets the number of bytes the user can store in Drive and logs it to the console. console.log(DriveApp.getStorageLimit());
리턴
Integer
- 사용자가 Drive에 저장할 수 있는 바이트 수입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getStorageUsed()
사용자가 현재 Drive에 저장하고 있는 바이트 수를 가져옵니다.
// Gets the number of bytes the user is currently storing in Drive and logs it to the console. console.log(DriveApp.getStorageUsed());
리턴
Integer
: 사용자가 현재 Drive에 저장하고 있는 바이트 수입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getTrashedFiles()
사용자 Drive의 휴지통에 있는 모든 파일의 컬렉션을 가져옵니다.
// Gets a list of all the files in the trash of the user's Drive. const trashFiles = DriveApp.getTrashedFiles(); // Logs the trash file names to the console. while (trashFiles.hasNext()) { const file = trashFiles.next(); console.log(file.getName()); }
리턴
FileIterator
- 휴지통에 있는 파일 모음입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getTrashedFolders()
사용자 Drive의 휴지통에 있는 모든 폴더의 컬렉션을 가져옵니다.
// Gets a collection of all the folders in the trash of the user's Drive. const trashFolders = DriveApp.getTrashedFolders(); // Logs the trash folder names to the console. while (trashFolders.hasNext()) { const folder = trashFolders.next(); console.log(folder.getName()); }
리턴
FolderIterator
- 휴지통에 있는 폴더 모음입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
searchFiles(params)
사용자의 드라이브에서 지정된 검색 기준과 일치하는 모든 파일의 컬렉션을 가져옵니다. 검색 기준은 Google Drive SDK 문서에 자세히 설명되어 있습니다. Drive 서비스는 Drive API v2를 사용하며 일부 쿼리 필드는 v3와 다릅니다. v2와 v3의 필드 차이를 검토하세요.
params
인수는 문자열 값을 포함할 수 있는 쿼리 문자열이므로 따옴표를 올바르게 이스케이프 처리해야 합니다 (예: "title contains 'Gulliver\\'s
Travels'"
또는 'title contains "Gulliver\'s Travels"'
).
// Logs the name of every file in the user's Drive that modified after February 28, // 2022 whose name contains "untitled."" var files = DriveApp.searchFiles( 'modifiedDate > "2022-02-28" and title contains "untitled"'); while (files.hasNext()) { var file = files.next(); console.log(file.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
params | String | 검색 기준(Google Drive SDK 문서에 설명됨) |
리턴
FileIterator
- 검색 기준과 일치하는 사용자 드라이브의 모든 파일 모음입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
searchFolders(params)
사용자의 드라이브에서 지정된 검색 기준과 일치하는 모든 폴더의 컬렉션을 가져옵니다. 검색 기준은 Google Drive SDK 문서에 자세히 설명되어 있습니다. Drive 서비스는 Drive API v2를 사용하며 일부 쿼리 필드는 v3와 다릅니다. v2와 v3의 필드 차이를 검토하세요.
params
인수는 문자열 값을 포함할 수 있는 쿼리 문자열이므로 따옴표를 올바르게 이스케이프 처리해야 합니다 (예: "title contains 'Gulliver\\'s
Travels'"
또는 'title contains "Gulliver\'s Travels"'
).
// Logs the name of every folder in the user's Drive that you own and is starred. var folders = DriveApp.searchFolders('starred = true and "me" in owners'); while (folders.hasNext()) { var folder = folders.next(); console.log(folder.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
params | String | 검색 기준(Google Drive SDK 문서에 설명됨) |
리턴
FolderIterator
- 사용자 드라이브에서 검색 기준과 일치하는 모든 폴더 컬렉션입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive