Google Drive의 파일입니다. DriveApp
에서 파일에 액세스하거나 생성할 수 있습니다.
// Trash every untitled spreadsheet that hasn't been updated in a week. var files = DriveApp.getFilesByName('Untitled spreadsheet'); while (files.hasNext()) { var file = files.next(); if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) { file.setTrashed(true); } }
방법
메서드 | 반환 유형 | 간략한 설명 |
---|---|---|
addCommenter(emailAddress) | File | 지정된 사용자를 File 의 댓글 작성자 목록에 추가합니다. |
addCommenter(user) | File | 지정된 사용자를 File 의 댓글 작성자 목록에 추가합니다. |
addCommenters(emailAddresses) | File | 지정된 사용자 배열을 File 의 댓글 작성자 목록에 추가합니다. |
addEditor(emailAddress) | File | 지정된 사용자를 File 의 편집자 목록에 추가합니다. |
addEditor(user) | File | 지정된 사용자를 File 의 편집자 목록에 추가합니다. |
addEditors(emailAddresses) | File | 지정된 사용자 배열을 File 의 편집자 목록에 추가합니다. |
addViewer(emailAddress) | File | 지정된 사용자를 File 의 뷰어 목록에 추가합니다. |
addViewer(user) | File | 지정된 사용자를 File 의 뷰어 목록에 추가합니다. |
addViewers(emailAddresses) | File | 지정된 사용자 배열을 File 의 뷰어 목록에 추가합니다. |
getAccess(email) | Permission | 지정된 사용자에게 부여된 권한을 가져옵니다. |
getAccess(user) | Permission | 지정된 사용자에게 부여된 권한을 가져옵니다. |
getAs(contentType) | Blob | 이 객체 내의 데이터를 지정된 콘텐츠 유형으로 변환된 blob으로 반환합니다. |
getBlob() | Blob | 이 객체 내의 데이터를 blob으로 반환합니다. |
getDateCreated() | Date | File 가 생성된 날짜를 가져옵니다. |
getDescription() | String | File 의 설명을 가져옵니다. |
getDownloadUrl() | String | 파일을 다운로드하는 데 사용할 수 있는 URL을 가져옵니다. |
getEditors() | User[] | 이 File 의 편집자 목록을 가져옵니다. |
getId() | String | File 의 ID를 가져옵니다. |
getLastUpdated() | Date | File 가 마지막으로 업데이트된 날짜를 가져옵니다. |
getMimeType() | String | 파일의 MIME 유형을 가져옵니다. |
getName() | String | File 의 이름을 가져옵니다. |
getOwner() | User | 파일 소유자를 가져옵니다. |
getParents() | FolderIterator | File 의 직계 상위 폴더 컬렉션을 가져옵니다. |
getResourceKey() | String | 링크를 사용하여 공유된 항목에 액세스하는 데 필요한 File 의 리소스 키를 가져옵니다. |
getSecurityUpdateEligible() | Boolean | 링크를 사용하여 공유할 때 이 File 에서 액세스를 위해 리소스 키가 필요한 보안 업데이트를 적용할 수 있는지 여부를 가져옵니다. |
getSecurityUpdateEnabled() | Boolean | 링크를 사용하여 공유할 때 이 File 에 액세스를 위한 리소스 키가 필요한지 여부를 가져옵니다. |
getSharingAccess() | Access | 명시적으로 액세스 권한이 부여된 개별 사용자 외에 File 에 액세스할 수 있는 사용자 클래스를 가져옵니다. |
getSharingPermission() | Permission | 명시적으로 액세스 권한이 부여된 개별 사용자 외에 File 에 액세스할 수 있는 사용자에게 부여된 권한을 가져옵니다. |
getSize() | Integer | Drive에 File 를 저장하는 데 사용되는 바이트 수를 가져옵니다. |
getTargetId() | String | 바로가기인 경우 가리키는 항목의 ID를 반환합니다. |
getTargetMimeType() | String | 바로가기인 경우 가리키는 항목의 MIME 유형을 반환합니다. |
getTargetResourceKey() | String | 파일이 바로가기인 경우 가리키는 항목의 리소스 키를 반환합니다. |
getThumbnail() | Blob | 파일의 미리보기 이미지를 가져오거나 null (썸네일이 없는 경우)을 가져옵니다. |
getUrl() | String | Drive 또는 Docs와 같은 Google 앱에서 File 을 여는 데 사용할 수 있는 URL을 가져옵니다. |
getViewers() | User[] | 이 File 의 뷰어 및 댓글 작성자 목록을 가져옵니다. |
isShareableByEditors() | Boolean | File 에 대한 수정 권한이 있는 사용자가 다른 사용자와 공유하거나 권한을 변경할 수 있는지 여부를 결정합니다. |
isStarred() | Boolean | File 가 사용자의 Drive에서 별표표시되었는지 확인합니다. |
isTrashed() | Boolean | File 이(가) 사용자 Drive의 휴지통에 있는지 확인합니다. |
makeCopy() | File | 파일 사본을 만듭니다. |
makeCopy(destination) | File | 대상 디렉터리에 파일의 사본을 만듭니다. |
makeCopy(name) | File | 파일 사본을 만들고 제공된 이름으로 이름을 지정합니다. |
makeCopy(name, destination) | File | 대상 디렉터리에 파일 사본을 만들고 제공된 이름으로 이름을 지정합니다. |
moveTo(destination) | File | 이 항목을 제공된 대상 폴더로 이동합니다. |
removeCommenter(emailAddress) | File | 지정된 사용자를 File 의 댓글 작성자 목록에서 삭제합니다. |
removeCommenter(user) | File | 지정된 사용자를 File 의 댓글 작성자 목록에서 삭제합니다. |
removeEditor(emailAddress) | File | 지정된 사용자를 File 의 편집자 목록에서 삭제합니다. |
removeEditor(user) | File | 지정된 사용자를 File 의 편집자 목록에서 삭제합니다. |
removeViewer(emailAddress) | File | File 의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. |
removeViewer(user) | File | File 의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. |
revokePermissions(emailAddress) | File | 지정된 사용자에게 부여된 File 에 대한 액세스 권한을 취소합니다. |
revokePermissions(user) | File | 지정된 사용자에게 부여된 File 에 대한 액세스 권한을 취소합니다. |
setContent(content) | File | 지정된 대체 항목으로 파일의 콘텐츠를 덮어씁니다. |
setDescription(description) | File | File 의 설명을 설정합니다. |
setName(name) | File | File 의 이름을 설정합니다. |
setOwner(emailAddress) | File | File 의 소유자를 변경합니다. |
setOwner(user) | File | File 의 소유자를 변경합니다. |
setSecurityUpdateEnabled(enabled) | File | 링크를 사용하여 공유할 때 File 에 액세스를 위한 리소스 키가 필요한지 여부를 설정합니다. |
setShareableByEditors(shareable) | File | File 에 대한 수정 권한이 있는 사용자가 다른 사용자와 공유하거나 권한을 변경할 수 있는지 여부를 설정합니다. |
setSharing(accessType, permissionType) | File | 명시적으로 액세스 권한이 부여된 개별 사용자 외에 File 에 액세스할 수 있는 사용자 클래스와 해당 사용자에게 부여할 권한을 설정합니다. |
setStarred(starred) | File | 사용자의 Drive에서 File 의 별표표시 여부를 설정합니다. |
setTrashed(trashed) | File | File 이(가) 사용자 Drive의 휴지통에 있는지 여부를 설정합니다. |
자세한 문서
addCommenter(emailAddress)
지정된 사용자를 File
의 댓글 작성자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 메서드는 사용자를 뷰어 목록에서 제거할 수 있습니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' with the email address that you // want to add as a commenter. while (files.hasNext()) { const file = files.next(); email = 'cloudysanfrancisco@gmail.com'; console.log(file.addCommenter(email)); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 추가할 사용자의 이메일 주소입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
addCommenter(user)
지정된 사용자를 File
의 댓글 작성자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 메서드는 사용자를 뷰어 목록에서 제거할 수 있습니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Adds the active user as a commenter. while (files.hasNext()) { const file = files.next(); file.addCommenter(Session.getActiveUser()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 추가할 사용자의 표현입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
addCommenters(emailAddresses)
지정된 사용자 배열을 File
의 댓글 작성자 목록에 추가합니다. 사용자가 이미 뷰어 목록에 있는 경우 이 메서드는 뷰어 목록에서 해당 사용자를 승격시킵니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); while (files.hasNext()) { const file = files.next(); // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' and // 'baklavainthebalkans@gmail.com' with the email addresses to add as commenters. const emails = ['cloudysanfrancisco@gmail.com','baklavainthebalkans@gmail.com']; console.log(file.addCommenters(emails)); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddresses | String[] | 추가할 사용자의 이메일 주소 배열입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
addEditor(emailAddress)
addEditor(user)
addEditors(emailAddresses)
addViewer(emailAddress)
addViewer(user)
addViewers(emailAddresses)
getAccess(email)
지정된 사용자에게 부여된 권한을 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
email | String | 권한을 확인해야 하는 사용자의 이메일 주소 |
리턴
Permission
: 사용자에게 부여된 권한
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getAccess(user)
지정된 사용자에게 부여된 권한을 가져옵니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 권한을 확인해야 하는 사용자의 표현 |
리턴
Permission
: 사용자에게 부여된 권한
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getAs(contentType)
이 객체 내의 데이터를 지정된 콘텐츠 유형으로 변환된 blob으로 반환합니다. 이 메서드는 파일 이름에 적절한 확장자(예: 'myfile.pdf')를 추가합니다. 그러나 파일 이름에서 마지막 마침표 다음에 오는 부분 (있는 경우)이 대체되어야 하는 기존 확장자라고 가정합니다. 따라서 'ShoppingList.12.25.2014'는 'ShoppingList.12.25.pdf'가 됩니다.
변환의 일일 할당량을 보려면 Google 서비스 할당량을 참조하세요. 새로 생성된 Google Workspace 도메인에는 일시적으로 더 엄격한 할당량이 적용될 수 있습니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
contentType | String | 변환할 MIME 유형입니다. 대부분의 blob에서 'application/pdf' 가 유일하게 유효한 옵션입니다. BMP, GIF, JPEG 또는 PNG 형식의 이미지의 경우 'image/bmp' , 'image/gif' , 'image/jpeg' , 'image/png' 중 어느 것도 사용할 수 있습니다. |
리턴
Blob
- blob 형식의 데이터입니다.
getBlob()
getDateCreated()
getDescription()
getDownloadUrl()
파일을 다운로드하는 데 사용할 수 있는 URL을 가져옵니다. Google Drive에서 파일을 열 수 있는 권한이 있는 사용자만 URL에 액세스할 수 있습니다. 브라우저에서 이 URL을 사용하여 파일을 다운로드할 수 있지만 UrlFetchApp
로 파일을 가져오는 데 사용할 수는 없습니다. 스크립트에 파일 콘텐츠를 포함하려면 getBlob()
를 사용합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the download URLs to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getDownloadUrl()); }
리턴
String
- 파일을 다운로드하는 데 사용할 수 있는 URL입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getEditors()
이 File
의 편집자 목록을 가져옵니다. 스크립트를 실행하는 사용자에게 File
에 대한 수정 액세스 권한이 없는 경우 이 메서드는 빈 배열을 반환합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Adds the email addresses in the array as editors of each file. // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' // and 'baklavainthebalkans@gmail.com' with valid email addresses. file.addEditors(['cloudysanfrancisco@gmail.com', 'baklavainthebalkans@gmail.com']); // Gets a list of the file editors. const editors = file.getEditors(); // For each file, logs the editors' email addresses to the console. for (const editor of editors) { console.log(editor.getEmail()); } }
리턴
User[]
- 사용자에게 이 File
의 수정 액세스 권한이 있는 경우 편집자 목록을 반환합니다. 사용자에게 수정 권한이 없으면 빈 배열을 반환합니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getId()
getLastUpdated()
getMimeType()
파일의 MIME 유형을 가져옵니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the MIME type to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getMimeType()); }
리턴
String
: 파일의 MIME 유형입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getName()
getOwner()
파일 소유자를 가져옵니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files and logs the names of the file owners to the console. while (files.hasNext()) { const file = files.next(); console.log(file.getOwner().getName()); }
리턴
User
- 파일 소유자입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getParents()
File
의 직계 상위 폴더 컬렉션을 가져옵니다.
리턴
FolderIterator
: File
의 직계 상위 폴더인 폴더 컬렉션
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getResourceKey()
getSecurityUpdateEligible()
링크를 사용하여 공유할 때 이 File
에서 액세스를 위해 리소스 키가 필요한 보안 업데이트를 적용할 수 있는지 여부를 가져옵니다.
Drive에서 링크를 사용하여 공유된 일부 파일 또는 폴더에 액세스하려면 리소스 키가 필요합니다. 이 변경사항은 보안 업데이트의 일부입니다. 업데이트는 요건을 충족하는 파일 및 폴더에 기본적으로 사용 설정됩니다. 요건을 충족하는 파일에 대해 리소스 키 요구사항을 사용 설정 또는 중지하려면 setSecurityUpdateEnabled
를 사용합니다.
Google Drive 보안 업데이트에 대해 자세히 알아보세요.
리턴
Boolean
: 리소스 키 요구사항을 File
에 적용할 수 있는지 여부입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSecurityUpdateEnabled()
링크를 사용하여 공유할 때 이 File
에 액세스를 위한 리소스 키가 필요한지 여부를 가져옵니다. 이 요구사항은 요건을 충족하는 파일 및 폴더에 기본적으로 사용 설정되어 있습니다.
요건을 충족하는 파일에 대해 리소스 키 요구사항을 사용 또는 사용 중지하려면
setSecurityUpdateEnabled
를 사용하세요.
Google Drive 보안 업데이트에 대해 자세히 알아보세요.
리턴
Boolean
: 이 File
에 리소스 키 요구사항이 사용 설정되어 있는지 여부입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSharingAccess()
getSharingPermission()
명시적으로 액세스 권한이 부여된 개별 사용자 외에 File
에 액세스할 수 있는 사용자에게 부여된 권한을 가져옵니다.
리턴
Permission
: File
에 액세스할 수 있는 사용자에게 부여된 권한
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSize()
getTargetId()
바로가기인 경우 가리키는 항목의 ID를 반환합니다.
그렇지 않으면 null
을 반환합니다.
// The ID of the file for which to make a shortcut and the ID of // the folder to which you want to add the shortcut. // TODO(developer): Replace the file and folder IDs with your IDs. const fileId = 'abc123456'; const folderId = 'xyz987654'; // Gets the folder to add the shortcut to. const folder = DriveApp.getFolderById(folderId); // Creates a shortcut of the file and moves it to the specified folder. const shortcut = DriveApp.createShortcut(fileId).moveTo(folder); // Logs the target ID of the shortcut. console.log(`${shortcut.getName()}=${shortcut.getTargetId()}`);
리턴
String
: 대상 항목 ID입니다.
getTargetMimeType()
바로가기인 경우 가리키는 항목의 MIME 유형을 반환합니다.
그렇지 않으면 null
을 반환합니다.
// The ID of the file for which to make a shortcut and the ID of // the folder to which you want to add the shortcut. // TODO(developer): Replace the file and folder IDs with your IDs. const fileId = 'abc123456'; const folderId = 'xyz987654'; // Gets the folder to add the shortcut to. const folder = DriveApp.getFolderById(folderId); // Creates a shortcut of the file and moves it to the specified folder. const shortcut = DriveApp.createShortcut(fileId).moveTo(folder); // Logs the MIME type of the file that the shortcut points to. console.log(`MIME type of the shortcut: ${shortcut.getTargetMimeType()}`);
리턴
String
- 타겟 항목 MIME 유형입니다.
getTargetResourceKey()
파일이 바로가기인 경우 가리키는 항목의 리소스 키를 반환합니다. 리소스 키는 링크를 사용하여 공유된 파일에 액세스하기 위해 전달해야 하는 추가 매개변수입니다.
파일이 바로가기가 아니면 null
을 반환합니다.
// Gets a file by its ID. // TODO(developer): Replace 'abc123456' with your file ID. const file = DriveApp.getFileById('abc123456'); // If the file is a shortcut, returns the resource key of the file that it points to. console.log(file.getTargetResourceKey());
리턴
String
- 대상 항목의 리소스 키 또는 null
(파일이 바로가기가 아닌 경우)입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getThumbnail()
파일의 미리보기 이미지를 가져오거나 null
(썸네일이 없는 경우)을 가져옵니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Logs the thumbnail image for each file to the console as a blob, // or null if no thumbnail exists. console.log(file.getThumbnail()); }
리턴
Blob
- 파일의 썸네일 이미지입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getUrl()
getViewers()
이 File
의 뷰어 및 댓글 작성자 목록을 가져옵니다. 스크립트를 실행하는 사용자에게 File
에 대한 수정 액세스 권한이 없으면 이 메서드는 빈 배열을 반환합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // For each file, logs the viewers' email addresses to the console. const viewers = file.getViewers(); for (viewer of viewers) { console.log(viewer.getEmail()); } }
리턴
User[]
- 사용자에게 이 File
에 대한 수정 액세스 권한이 있는 경우 뷰어 및 댓글 작성자 목록을 반환합니다. 사용자에게 수정 권한이 없으면 빈 배열을 반환합니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
isStarred()
isTrashed()
makeCopy()
파일 사본을 만듭니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and logs the file name to the console. console.log(file.makeCopy().getName()); }
리턴
File
- 새 사본입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
makeCopy(destination)
대상 디렉터리에 파일의 사본을 만듭니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and adds it to the specified folder. // TODO(developer): Replace the folder ID with your own. const destination = DriveApp.getFolderById('123456abcxyz'); const copiedFile = file.makeCopy(destination); // Logs the file names to the console. console.log(copiedFile.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
destination | Folder | 파일을 복사할 디렉터리입니다. |
리턴
File
- 새 사본입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
makeCopy(name)
파일 사본을 만들고 제공된 이름으로 이름을 지정합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file and sets the name to 'Test-Copy.' const filename = file.makeCopy('Test-Copy'); // Logs the copied file's name to the console. console.log(filename.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 새 사본에 적용해야 하는 파일 이름입니다. |
리턴
File
- 새 사본입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
makeCopy(name, destination)
대상 디렉터리에 파일 사본을 만들고 제공된 이름으로 이름을 지정합니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Creates a copy of each file, sets the file name, and adds the copied file // to the specified folder. // TODO(developer): Replace the folder ID with your own. const destination = DriveApp.getFolderById('123456abcxyz'); const copiedFile = file.makeCopy('Test-Copy', destination); // Logs the file names to the console. console.log(copiedFile.getName()); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
name | String | 새 사본에 적용해야 하는 파일 이름입니다. |
destination | Folder | 파일을 복사할 디렉터리입니다. |
리턴
File
- 새 사본입니다.
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
moveTo(destination)
removeCommenter(emailAddress)
지정된 사용자를 File
의 댓글 작성자 목록에서 삭제합니다. 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 사용자(예: File
가 사용자의 전체 도메인과 공유되는 경우)에 속하는 사용자의 File
액세스를 차단하지 않습니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Removes the given user from the list of commenters for each file. // TODO(developer): Replace the email with the email of the user you want to remove. file.removeCommenter('cloudysanfrancisco@gmail.com'); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 삭제할 사용자의 이메일 주소입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
removeCommenter(user)
지정된 사용자를 File
의 댓글 작성자 목록에서 삭제합니다. 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 사용자(예: File
가 사용자의 전체 도메인과 공유되는 경우)에 속하는 사용자의 File
액세스를 차단하지 않습니다.
// Gets a list of all files in Google Drive with the given name. // TODO(developer): Replace the file name with your own. const files = DriveApp.getFilesByName('Test'); // Loops through the files. while (files.hasNext()) { const file = files.next(); // Removes the given user from the list of commenters for each file. console.log(file.removeCommenter(Session.getActiveUser())); }
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 삭제할 사용자의 표현입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
removeEditor(emailAddress)
지정된 사용자를 File
의 편집자 목록에서 삭제합니다. 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: File
가 사용자의 전체 도메인과 공유되거나 File
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 이 메서드는 사용자가 File
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 삭제할 사용자의 이메일 주소입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
removeEditor(user)
지정된 사용자를 File
의 편집자 목록에서 삭제합니다. 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: File
가 사용자의 전체 도메인과 공유되거나 File
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) 이 메서드는 사용자가 File
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 뷰어 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 삭제할 사용자의 표현입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
removeViewer(emailAddress)
File
의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 사용자가 뷰어나 댓글 작성자가 아닌 편집자인 경우에는 이 메서드가 영향을 미치지 않습니다. 또한 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: File
가 사용자의 전체 도메인과 공유되거나 File
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) File
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
emailAddress | String | 삭제할 사용자의 이메일 주소입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
removeViewer(user)
File
의 뷰어 및 댓글 작성자 목록에서 지정된 사용자를 삭제합니다. 사용자가 뷰어가 아닌 편집자인 경우에는 이 메서드가 영향을 미치지 않습니다. 또한 이 메서드는 일반 액세스 권한이 있는 사용자 클래스에 속한 경우(예: File
가 사용자의 전체 도메인과 공유되거나 File
가 사용자가 액세스할 수 있는 공유 드라이브에 있는 경우) File
에 액세스하는 것을 차단하지 않습니다.
Drive 파일의 경우 편집자 목록에서도 사용자가 삭제됩니다.
매개변수
이름 | 유형 | 설명 |
---|---|---|
user | User | 삭제할 사용자의 표현입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
revokePermissions(emailAddress)
revokePermissions(user)
setContent(content)
지정된 대체 항목으로 파일의 콘텐츠를 덮어씁니다. content
가 10MB보다 크면 예외가 발생합니다.
// Creates a text file with the content 'Hello, world!' file = DriveApp.createFile('New Text File', 'Hello, world!'); // Logs the content of the text file to the console. console.log(file.getBlob().getDataAsString()); // Updates the content of the text file to 'Updated text!' file.setContent('Updated text!') // Logs content of the text file to the console. console.log(file.getBlob().getDataAsString());
매개변수
이름 | 유형 | 설명 |
---|---|---|
content | String | 파일의 새 콘텐츠입니다. |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive
setDescription(description)
setName(name)
setOwner(emailAddress)
setOwner(user)
setSecurityUpdateEnabled(enabled)
setSharing(accessType, permissionType)
명시적으로 액세스 권한이 부여된 개별 사용자 외에 File
에 액세스할 수 있는 사용자 클래스와 해당 사용자에게 부여할 권한을 설정합니다.
// Creates a folder that anyone on the Internet can read from and write to. (Domain // administrators can prohibit this setting for users of a Google Workspace domain.) var folder = DriveApp.createFolder('Shared Folder'); folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
매개변수
이름 | 유형 | 설명 |
---|---|---|
accessType | Access | File 에 액세스할 수 있는 사용자 클래스 |
permissionType | Permission | File 에 액세스할 수 있는 사용자에게 부여해야 하는 권한 |
리턴
승인
이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.
-
https://www.googleapis.com/auth/drive