Google ドライブ内のファイル。ファイルは 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); } }
Methods
メソッド | 戻り値の型 | 概要 |
---|---|---|
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 | ドライブに File を保存するために使用されるバイト数を取得します。 |
getTargetId() | String | ショートカットの場合は、キーが指しているアイテムの ID を返します。 |
getTargetMimeType() | String | ショートカットの場合、ポイントしているアイテムの MIME タイプを返します。 |
getTargetResourceKey() | String | ファイルがショートカットの場合は、それが指しているアイテムのリソースキーを返します。 |
getThumbnail() | Blob | ファイルのサムネイル画像を取得します。サムネイルが存在しない場合は null を取得します。 |
getUrl() | String | ドライブやドキュメントなどの Google アプリで File を開くために使用できる URL を取得します。 |
getViewers() | User[] | この File の閲覧者とコメント投稿者のリストを取得します。 |
isShareableByEditors() | Boolean | File に対する編集権限を持つユーザーに、他のユーザーと共有したり、権限を変更したりできるかどうかを決定します。 |
isStarred() | Boolean | ユーザーのドライブで File にスターが付いているかどうかを判断します。 |
isTrashed() | Boolean | File がユーザーのドライブのゴミ箱にあるかどうかを判断します。 |
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 | ユーザーのドライブで File にスターを付けるかどうかを設定します。 |
setTrashed(trashed) | File | File がユーザーのドライブのゴミ箱にあるかどうかを設定します。 |
詳細なドキュメント
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 | 追加するユーザーのメールアドレス。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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 | 追加するユーザーの表現。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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[] | 追加するユーザーのメールアドレスの配列。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
addEditor(emailAddress)
addEditor(user)
addEditors(emailAddresses)
addViewer(emailAddress)
addViewer(user)
addViewers(emailAddresses)
getAccess(email)
指定されたユーザーに付与された権限を取得します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
email | String | 権限を確認するユーザーのメールアドレス |
リターン
Permission
- ユーザーに付与される権限
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getAccess(user)
指定されたユーザーに付与された権限を取得します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 権限を確認する必要があるユーザーの表現 |
リターン
Permission
- ユーザーに付与される権限
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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」になります。
コンバージョンの 1 日あたりの割り当てを確認するには、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 ドライブでファイルを開く権限を持つユーザーのみが 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。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
の編集権限を持っている場合、編集者のリストを返します。ユーザーに編集権限がない場合は空の配列を返します。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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 タイプ。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- ファイルのオーナー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getParents()
File
の直接の親であるフォルダのコレクションを取得します。
リターン
FolderIterator
- File
の直接の親であるフォルダのコレクション
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getResourceKey()
getSecurityUpdateEligible()
この File
がリンクで共有されたときに、アクセスにリソースキーを必要とするセキュリティ アップデートの適用が可能かどうかを取得します。
リンクを使用して共有されたファイルやフォルダにアクセスするには、ドライブがリソースキーを必要とします。この変更はセキュリティ アップデートの一部です。対象となるファイルとフォルダの更新はデフォルトでオンになっています。対象となるファイルに対してリソースキーの要件をオンまたはオフにするには、setSecurityUpdateEnabled
を使用します。
詳しくは、Google ドライブのセキュリティ アップデートをご覧ください。
リターン
Boolean
- リソースキーの要件を File
に適用できるかどうか。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSecurityUpdateEnabled()
この File
がリンクで共有される場合、アクセスのためにリソースキーが必要かどうかを取得します。この要件は、対象となるファイルとフォルダに対してデフォルトでオンになっています。
対象となるファイルに対してリソースキーの要件をオンまたはオフにするには、
setSecurityUpdateEnabled
を使用します。
詳しくは、Google ドライブのセキュリティ アップデートをご覧ください。
リターン
Boolean
- この File
でリソースキーの要件が有効になっているかどうか。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getSharingAccess()
getSharingPermission()
明示的にアクセス権が付与されている個々のユーザーに加え、File
にアクセスできるユーザーに付与されている権限を取得します。
リターン
Permission
- File
にアクセスできるユーザーに付与される権限
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- ファイルのサムネイル画像。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
の編集権限がある場合、閲覧者とコメント投稿者のリストを返します。ユーザーに編集権限がない場合は空の配列を返します。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- 新しいコピー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- 新しいコピー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- 新しいコピー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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
- 新しいコピー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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 | 削除するユーザーのメールアドレス。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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 | 削除するユーザーの表現。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
removeEditor(emailAddress)
File
の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが File
にアクセスすることをブロックしません。たとえば、File
がユーザーのドメイン全体と共有されている場合や、File
がユーザーがアクセスできる共有ドライブ内にある場合です。
ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
removeEditor(user)
File
の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが File
にアクセスすることをブロックしません。たとえば、File
がユーザーのドメイン全体と共有されている場合や、File
がユーザーがアクセスできる共有ドライブ内にある場合です。
ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
removeViewer(emailAddress)
File
の閲覧者とコメント投稿者のリストから、指定されたユーザーを削除します。ユーザーが閲覧者やコメント投稿者ではなく編集者の場合、このメソッドは効力を持ちません。また、このメソッドによって、ユーザーが一般的なアクセス権を持つユーザーのクラスに属している場合(たとえば、File
がユーザーのドメイン全体と共有されている場合や、File
がユーザーがアクセスできる共有ドライブ内にある場合)は、File
へのアクセスがブロックされません。
ドライブ ファイルの場合、編集者のリストからもユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
removeViewer(user)
File
の閲覧者とコメント投稿者のリストから、指定されたユーザーを削除します。ユーザーが閲覧者ではなく編集者の場合、このメソッドは効力がありません。また、File
がユーザーのドメイン全体と共有されている場合や、File
がユーザーがアクセスできる共有ドライブ内にある場合など、一般的なアクセス権を持つユーザーのクラスに所属しているユーザーも、File
にアクセスすることはブロックされません。
ドライブ ファイルの場合、編集者のリストからもユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive
revokePermissions(emailAddress)
revokePermissions(user)
setContent(content)
指定した置換でファイルの内容を上書きします。content
が 10 MB より大きい場合、例外をスローします。
// 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 | ファイルの新しいコンテンツ。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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 にアクセスできるユーザーに付与する必要がある権限。 |
リターン
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/drive