Class Folder

資料夾

Google 雲端硬碟中的資料夾。您可以透過 DriveApp 存取或建立資料夾。

// Log the name of every folder in the user's Drive.
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
  var folder = folders.next();
  Logger.log(folder.getName());
}

方法

方法傳回類型簡短說明
addEditor(emailAddress)Folder將指定的使用者新增至 Folder 的編輯者清單。
addEditor(user)Folder將指定的使用者新增至 Folder 的編輯者清單。
addEditors(emailAddresses)Folder將指定的使用者陣列新增至 Folder 的編輯者清單。
addViewer(emailAddress)Folder將指定的使用者新增至 Folder 的檢視者清單。
addViewer(user)Folder將指定的使用者新增至 Folder 的檢視者清單。
addViewers(emailAddresses)Folder將指定的使用者陣列新增至 Folder 的檢視者清單。
createFile(blob)File這個外掛程式能根據指定的 Blob 任意資料,在目前的資料夾中建立檔案。
createFile(name, content)File以指定名稱和內容在目前資料夾中建立文字檔案。
createFile(name, content, mimeType)File以指定名稱、內容和 MIME 類型在目前資料夾中建立檔案。
createFolder(name)Folder在目前資料夾中建立具有指定名稱的資料夾。
createShortcut(targetId)File針對您提供的雲端硬碟項目 ID 建立捷徑,然後傳回該捷徑。
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)File針對提供的雲端硬碟項目 ID 和資源鍵建立捷徑,然後傳回該捷徑。
getAccess(email)Permission取得已授予指定使用者的權限。
getAccess(user)Permission取得已授予指定使用者的權限。
getDateCreated()Date取得 Folder 的建立日期。
getDescription()String取得 Folder 的說明。
getEditors()User[]取得這個 Folder 的編輯者清單。
getFiles()FileIterator取得目前資料夾子項的所有檔案的集合。
getFilesByName(name)FileIterator取得目前資料夾子項的所有檔案集合,且擁有指定名稱。
getFilesByType(mimeType)FileIterator取得目前資料夾子項,且具備指定 MIME 類型的所有檔案集合。
getFolders()FolderIterator取得目前資料夾子項的所有資料夾集合。
getFoldersByName(name)FolderIterator取得目前資料夾子項的所有資料夾集合,且擁有指定名稱。
getId()String取得 Folder 的 ID。
getLastUpdated()Date取得 Folder 的上次更新時間。
getName()String取得 Folder 的名稱。
getOwner()User取得此Folder的擁有者。
getParents()FolderIterator取得一組是 Folder 直接父項的資料夾。
getResourceKey()String取得 Folder 的資源金鑰,以便存取透過連結共用的項目。
getSecurityUpdateEligible()Boolean取得此 Folder 是否符合資格,可套用透過連結共用時,需要資源金鑰才能存取的安全性更新。
getSecurityUpdateEnabled()Boolean取得此 Folder 是否需要透過連結分享時需要資源金鑰才能存取。
getSharingAccess()Access取得哪些使用者類別可以存取 Folder,但不侷限於任何已明確授予存取權的個別使用者。
getSharingPermission()Permission取得將權限授予可存取 Folder 的使用者,以及任何明確獲得存取權的個別使用者。
getSize()Integer取得在雲端硬碟中儲存 Folder 的位元組數。
getUrl()String取得可用於在雲端硬碟或文件等 Google 應用程式中開啟 Folder 的網址。
getViewers()User[]取得此Folder的檢視者和加註者清單。
isShareableByEditors()Boolean決定擁有 Folder 編輯權限的使用者,是否可與其他使用者共用或變更權限。
isStarred()Boolean判斷使用者的雲端硬碟中是否已為 Folder 加上星號。
isTrashed()Boolean判斷 Folder 是否在使用者的雲端硬碟垃圾桶中。
moveTo(destination)Folder將這個項目移至提供的目標資料夾。
removeEditor(emailAddress)Folder將指定使用者從 Folder 的編輯者清單中移除。
removeEditor(user)Folder將指定使用者從 Folder 的編輯者清單中移除。
removeViewer(emailAddress)Folder將特定使用者從「Folder」的檢視者和加註者清單中移除。
removeViewer(user)Folder將特定使用者從「Folder」的檢視者和加註者清單中移除。
revokePermissions(emailAddress)Folder撤銷已授予特定使用者 Folder 的存取權。
revokePermissions(user)Folder撤銷已授予特定使用者 Folder 的存取權。
searchFiles(params)FileIterator取得目前資料夾子項且符合指定搜尋條件的所有檔案的集合。
searchFolders(params)FolderIterator取得目前資料夾子項且符合指定搜尋條件的所有資料夾集合。
setDescription(description)Folder設定 Folder 的說明。
setName(name)Folder設定 Folder 的名稱。
setOwner(emailAddress)Folder變更 Folder 的擁有者。
setOwner(user)Folder變更 Folder 的擁有者。
setSecurityUpdateEnabled(enabled)Folder設定透過連結分享 Folder 時,是否需要資源金鑰才能存取。
setShareableByEditors(shareable)Folder設定是否允許具有 Folder 編輯權限的使用者與其他使用者共用或變更權限。
setSharing(accessType, permissionType)Folder設定哪些使用者類別可以存取 Folder,以及授予這些使用者的權限,但不包括明確獲得存取權的個別使用者。
setStarred(starred)Folder設定是否要在使用者的雲端硬碟中為 Folder 加上星號。
setTrashed(trashed)Folder設定 Folder 是否在使用者的雲端硬碟垃圾桶中。

內容詳盡的說明文件

addEditor(emailAddress)

將指定的使用者新增至 Folder 的編輯者清單。如果使用者已在檢視者清單中,這個方法會在檢視者清單中推薦使用者。

參數

名稱類型說明
emailAddressString要新增的使用者電子郵件地址。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

addEditor(user)

將指定的使用者新增至 Folder 的編輯者清單。如果使用者已在檢視者清單中,這個方法會在檢視者清單中推薦使用者。

參數

名稱類型說明
userUser代表要新增的使用者。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

addEditors(emailAddresses)

將指定的使用者陣列新增至 Folder 的編輯者清單。如有任何使用者已列在檢視者清單中,這個方法會將這些使用者從觀眾清單中移除。

參數

名稱類型說明
emailAddressesString[]要新增的使用者電子郵件地址陣列。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

addViewer(emailAddress)

將指定的使用者新增至 Folder 的檢視者清單。如果使用者已列在編輯者清單中,這個方法就不會有任何作用。

參數

名稱類型說明
emailAddressString要新增的使用者電子郵件地址。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

addViewer(user)

將指定的使用者新增至 Folder 的檢視者清單。如果使用者已列在編輯者清單中,這個方法就不會有任何作用。

參數

名稱類型說明
userUser代表要新增的使用者。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

addViewers(emailAddresses)

將指定的使用者陣列新增至 Folder 的檢視者清單。如有任何使用者已列在編輯者清單中,這個方法就不會對他們造成任何影響。

參數

名稱類型說明
emailAddressesString[]要新增的使用者電子郵件地址陣列。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createFile(blob)

這個外掛程式能根據指定的 Blob 任意資料,在目前的資料夾中建立檔案。

// Create an image file in Google Drive using the Maps service.
var blob = Maps.newStaticMap().setCenter('76 9th Avenue, New York NY').getBlob();
DriveApp.getRootFolder().createFile(blob);

參數

名稱類型說明
blobBlobSource新檔案的資料。

回攻員

File:新檔案。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createFile(name, content)

以指定名稱和內容在目前資料夾中建立文字檔案。如果 content 大於 50 MB,就會擲回例外狀況。

// Create a text file with the content "Hello, world!"
DriveApp.getRootFolder().createFile('New Text File', 'Hello, world!');

參數

名稱類型說明
nameString新檔案的名稱。
contentString新檔案的內容。

回攻員

File:新檔案。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createFile(name, content, mimeType)

以指定名稱、內容和 MIME 類型在目前資料夾中建立檔案。如果 content 大於 10 MB,就會擲回例外狀況。

// Create an HTML file with the content "Hello, world!"
DriveApp.getRootFolder().createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);

參數

名稱類型說明
nameString新檔案的名稱。
contentString新檔案的內容。
mimeTypeString新檔案的 MIME 類型。

回攻員

File:新檔案。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createFolder(name)

在目前資料夾中建立具有指定名稱的資料夾。

參數

名稱類型說明
nameString新資料夾的名稱。

回攻員

Folder:新資料夾。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createShortcut(targetId)

針對您提供的雲端硬碟項目 ID 建立捷徑,然後傳回該捷徑。

參數

名稱類型說明
targetIdString目標檔案或資料夾的檔案 ID。

回攻員

File:新的快速鍵。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)

針對提供的雲端硬碟項目 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());
}

參數

名稱類型說明
targetIdString目標檔案或資料夾的 ID。
targetResourceKeyString目標檔案或資料夾的資源金鑰。

回攻員

File:新的快速鍵。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

getAccess(email)

取得已授予指定使用者的權限。

參數

名稱類型說明
emailString應檢查其權限的使用者電子郵件地址

回攻員

Permission:授予使用者的權限

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getAccess(user)

取得已授予指定使用者的權限。

參數

名稱類型說明
userUser代表應檢查其權限的使用者

回攻員

Permission:授予使用者的權限

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getDateCreated()

取得 Folder 的建立日期。

回攻員

DateFolder 的建立日期

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getDescription()

取得 Folder 的說明。

回攻員

StringFolder 的說明

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getEditors()

取得這個 Folder 的編輯者清單。如果執行指令碼的使用者沒有 Folder 的編輯權限,這個方法會傳回空陣列。

// Gets a folder by its ID.
// TODO(developer): Replace the folder ID with your own.
const folder = DriveApp.getFolderById('1234567890abcdefghijklmnopqrstuvwxyz');

// Gets the list of editors and logs their names to the console.
const editors = folder.getEditors();
for (editor of editors) {
  console.log(editor.getName());
}

回攻員

User[]:如果使用者俱有編輯權限,則這個 Folder 的編輯者清單;如果沒有編輯權限,則為空白陣列。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • 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)

取得目前資料夾子項的所有檔案集合,且擁有指定名稱。

參數

名稱類型說明
nameString要尋找的檔案名稱。

回攻員

FileIterator:屬於目前資料夾子項且具有指定名稱的所有檔案集合。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getFilesByType(mimeType)

取得目前資料夾子項,且具備指定 MIME 類型的所有檔案集合。

參數

名稱類型說明
mimeTypeString要尋找的 MIME 類型檔案。

回攻員

FileIterator:屬於目前資料夾子項,且具備指定 MIME 類型的所有檔案集合。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • 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)

取得目前資料夾子項的所有資料夾集合,且擁有指定名稱。

參數

名稱類型說明
nameString要尋找的資料夾名稱。

回攻員

FolderIterator:屬於目前資料夾子項且具有指定名稱的所有資料夾。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getId()

取得 Folder 的 ID。

回攻員

StringFolder 的 ID

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getLastUpdated()

取得 Folder 的上次更新時間。

回攻員

DateFolder的上次更新時間

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getName()

取得 Folder 的名稱。

回攻員

StringFolder 的名稱

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getOwner()

取得此 Folder 的擁有者。

// Gets a folder by its ID.
// TODO(developer): Replace the folder ID with your own.
const folder = DriveApp.getFolderById('1234567890abcdefghijklmnopqrstuvwxyz');

// Gets the owner of the folder and logs the name to the console.
const folderOwner = folder.getOwner();
console.log(folderOwner.getName());

回攻員

UserFolder的擁有者。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getParents()

取得一組是 Folder 直接父項的資料夾。

回攻員

FolderIterator:具備 Folder 立即父項的一組資料夾

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getResourceKey()

取得 Folder 的資源金鑰,以便存取透過連結共用的項目。

回攻員

StringFolder 的資源金鑰。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getSecurityUpdateEligible()

取得此 Folder 是否符合資格,可套用透過連結共用時,需要資源金鑰才能存取的安全性更新。

雲端硬碟需要資源金鑰才能存取透過連結共用的部分檔案或資料夾。這項變更屬於安全性更新的一部分。針對符合條件的檔案和資料夾,系統預設會開啟更新。如要開啟或關閉符合資格的檔案的資源金鑰需求,請使用 setSecurityUpdateEnabled

進一步瞭解 Google 雲端硬碟的安全性更新

回攻員

Boolean:是否可對 Folder 套用資源金鑰要求。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getSecurityUpdateEnabled()

取得此 Folder 是否需要透過連結分享時需要資源金鑰才能存取。系統會為符合資格的檔案和資料夾預設啟用這項規定。 如要開啟或關閉符合資格的檔案的資源金鑰需求,請使用 setSecurityUpdateEnabled

進一步瞭解 Google 雲端硬碟的安全性更新

回攻員

Boolean:指出這個Folder是否已啟用資源金鑰需求。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getSharingAccess()

取得哪些使用者類別可以存取 Folder,但不侷限於任何已明確授予存取權的個別使用者。

回攻員

Access:可以存取 Folder 的使用者類別

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getSharingPermission()

取得將權限授予可存取 Folder 的使用者,以及任何明確獲得存取權的個別使用者。

回攻員

Permission:授予可存取 Folder 的使用者的權限

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getSize()

取得在雲端硬碟中儲存 Folder 的位元組數。請注意,Google Workspace 應用程式檔案不會計入雲端硬碟儲存空間上限,因此會傳回 0 個位元組。

回攻員

Integer:在雲端硬碟中儲存 Folder 的位元組數

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getUrl()

取得可用於在雲端硬碟或文件等 Google 應用程式中開啟 Folder 的網址。

回攻員

String:可在 Google 應用程式 (例如 Google 雲端硬碟或 Google 文件) 中查看這個 Folder 的網址

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

getViewers()

取得此Folder的檢視者和加註者清單。如果執行指令碼的使用者沒有 Folder 的編輯權限,這個方法會傳回空陣列。

// Gets a folder by its ID.
// TODO(developer): Replace the folder ID with your own.
const folder = DriveApp.getFolderById('1234567890abcdefghijklmnopqrstuvwxyz');

// Gets the list of viewers and logs their names to the console.
const viewers = folder.getViewers();
for (viewer of viewers) {
  console.log(viewer.getName());
}

回攻員

User[]:如果使用者擁有編輯權限,或是擁有空白陣列,此 Folder 的檢視者和加註者清單。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

isShareableByEditors()

決定擁有 Folder 編輯權限的使用者,是否可與其他使用者共用或變更權限。

回攻員

Boolean:如果具備編輯權限的使用者可與其他使用者共用項目,或變更權限,則設為 true;如果不是,則為 false

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

isStarred()

判斷使用者的雲端硬碟中是否已為 Folder 加上星號。

回攻員

Booleantrue 表示 Folder 已在使用者的雲端硬碟中加上星號;如果未在使用者的雲端硬碟中加上星號,則為 false

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

isTrashed()

判斷 Folder 是否在使用者的雲端硬碟垃圾桶中。

回攻員

Boolean:如果 Folder 在使用者雲端硬碟的垃圾桶中,則為 true;如果不在使用者的雲端硬碟垃圾桶中,則為 false

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

moveTo(destination)

將這個項目移至提供的目的地資料夾。

目前使用者必須是檔案的擁有者,或至少擁有項目目前上層資料夾的編輯權限,才能將項目移至目的地資料夾。

參數

名稱類型說明
destinationFolder要成為新父項的資料夾。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

removeEditor(emailAddress)

將指定使用者從 Folder 的編輯者清單中移除。如果使用者屬於具備一般存取權的使用者類別,此方法不會禁止使用者存取 Folder。舉例來說,如果 Folder 是與使用者整個網域共用,或是 Folder 位於該使用者可存取的共用雲端硬碟中,則他們無法這麼做。

若是雲端硬碟檔案,則也會將使用者從檢視者清單中移除。

參數

名稱類型說明
emailAddressString要移除的使用者電子郵件地址。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

removeEditor(user)

將指定使用者從 Folder 的編輯者清單中移除。如果使用者屬於具備一般存取權的使用者類別,此方法不會禁止使用者存取 Folder。舉例來說,如果 Folder 是與使用者整個網域共用,或是 Folder 位於該使用者可存取的共用雲端硬碟中,則他們無法這麼做。

若是雲端硬碟檔案,則也會將使用者從檢視者清單中移除。

參數

名稱類型說明
userUser代表要移除的使用者。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

removeViewer(emailAddress)

將特定使用者從「Folder」的檢視者和加註者清單中移除。如果使用者是編輯者,而非檢視者或加註者,這個方法就不會生效。此外,假如使用者屬於具有一般存取權的使用者類別,例如 Folder 已與使用者的整個網域共用,或 Folder 位於該使用者可存取的共用雲端硬碟中,此方法也不會阻止使用者存取 Folder

針對雲端硬碟檔案,這麼做也會將使用者從編輯者清單中移除。

參數

名稱類型說明
emailAddressString要移除的使用者電子郵件地址。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

removeViewer(user)

將特定使用者從「Folder」的檢視者和加註者清單中移除。如果使用者是編輯者,而不是檢視者,這個方法就不會生效。如果使用者屬於具有一般存取權的使用者類別,此方法也不會禁止使用者存取 Folder。例如,假設 Folder 是與使用者整個網域共用,或是 Folder 位於該使用者可存取的共用雲端硬碟中。

針對雲端硬碟檔案,這麼做也會將使用者從編輯者清單中移除。

參數

名稱類型說明
userUser代表要移除的使用者。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

revokePermissions(emailAddress)

撤銷已授予特定使用者 Folder 的存取權。如果使用者屬於具有一般存取權的使用者類別 (例如 Folder 與使用者整個網域共用),此方法不會禁止使用者存取 Folder

參數

名稱類型說明
emailAddressString應撤銷存取權的使用者電子郵件地址。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

revokePermissions(user)

撤銷已授予特定使用者 Folder 的存取權。如果使用者屬於具有一般存取權的使用者類別 (例如 Folder 與使用者整個網域共用),此方法不會禁止使用者存取 Folder

參數

名稱類型說明
userUser代表應撤銷存取權的使用者。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

searchFiles(params)

取得目前資料夾子項且符合指定搜尋條件的所有檔案的集合。如需搜尋條件的詳細說明,請參閱 Google 雲端硬碟 SDK 說明文件。請注意,雲端硬碟服務使用 v2 的 Drive API,且部分查詢欄位與 v3 不同。查看第 2 版和第 3 版的欄位差異

params 引數是可包含字串值的查詢字串,因此務必使用正確的逸出引號 (例如 "title contains 'Gulliver\\'s Travels'"'title contains "Gulliver\'s Travels"')。

// Logs the name of every file that are children of the current folder and modified after February 28,
// 2022 whose name contains "untitled.""
var files = DriveApp.getRootFolder().searchFiles(
    'modifiedDate > "2022-02-28" and title contains "untitled"');
while (files.hasNext()) {
  var file = files.next();
  console.log(file.getName());
}

參數

名稱類型說明
paramsString搜尋條件,詳情請參閱 Google 雲端硬碟 SDK 說明文件

回攻員

FileIterator:屬於目前資料夾子項且符合搜尋條件的所有檔案集合。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

searchFolders(params)

取得目前資料夾子項且符合指定搜尋條件的所有資料夾集合。如需搜尋條件的詳細說明,請參閱 Google 雲端硬碟 SDK 說明文件。請注意,雲端硬碟服務使用 v2 的 Drive API,且部分查詢欄位與 v3 不同。查看第 2 版和第 3 版的欄位差異

params 引數是可包含字串值的查詢字串,因此務必使用正確的逸出引號 (例如 "title contains 'Gulliver\\'s Travels'"'title contains "Gulliver\'s Travels"')。

// Logs the name of every folder that are children of the current folder and you own and is starred.
var folders = DriveApp.getRootFolder().searchFolders('starred = true and "me" in owners');
while (folders.hasNext()) {
  var folder = folders.next();
  console.log(folder.getName());
}

參數

名稱類型說明
paramsString搜尋條件,詳情請參閱 Google 雲端硬碟 SDK 說明文件

回攻員

FolderIterator:屬於目前資料夾子項且符合搜尋條件的所有資料夾。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive.readonly
  • https://www.googleapis.com/auth/drive

setDescription(description)

設定 Folder 的說明。

參數

名稱類型說明
descriptionStringFolder」的新說明

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setName(name)

設定 Folder 的名稱。

參數

名稱類型說明
nameStringFolder 的新名稱

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setOwner(emailAddress)

變更 Folder 的擁有者。這個方法也會向先前擁有者授予 Folder 的明確編輯權限。

參數

名稱類型說明
emailAddressString新擁有者的電子郵件地址

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setOwner(user)

變更 Folder 的擁有者。這個方法也會向先前擁有者授予 Folder 的明確編輯權限。

參數

名稱類型說明
userUser代表應成為新擁有者的使用者

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setSecurityUpdateEnabled(enabled)

設定透過連結分享 Folder 時,是否需要資源金鑰才能存取。符合資格的檔案和資料夾預設為啟用。

進一步瞭解 Google 雲端硬碟的安全性更新

參數

名稱類型說明
enabledBoolean是否要為 Folder 啟用資源金鑰需求。

回攻員

Folder — 此 Folder 用於鏈結。

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setShareableByEditors(shareable)

設定是否允許具有 Folder 編輯權限的使用者與其他使用者共用或變更權限。新 Folder 的預設值為 true

參數

名稱類型說明
shareableBoolean如果應允許擁有編輯權限的使用者與其他使用者共用或變更權限,則為 true;如果不是,則為 false

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setSharing(accessType, permissionType)

設定哪些使用者類別可以存取 Folder,以及授予這些使用者的權限,但不包括明確獲得存取權的個別使用者。

// 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);

參數

名稱類型說明
accessTypeAccess哪個類別的使用者應該可以存取 Folder
permissionTypePermission對於可存取 Folder 的使用者所能授予的權限

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setStarred(starred)

設定是否要在使用者的雲端硬碟中為 Folder 加上星號。新的 Folder 的預設值為 false

參數

名稱類型說明
starredBooleantrue 表示在使用者雲端硬碟中應為 Folder 加上星號;如果不是,則為 false

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

setTrashed(trashed)

設定 Folder 是否在使用者的雲端硬碟垃圾桶中。只有擁有者才能將 Folder 移至垃圾桶。新 Folder 的預設值為 false

參數

名稱類型說明
trashedBoolean如果 Folder 應移至使用者雲端硬碟的垃圾桶,則為 true;如果不是,則為 false

回攻員

Folder — 此 Folder,用於鏈結

授權

使用這個方法的指令碼必須取得以下一或多個範圍的授權:

  • https://www.googleapis.com/auth/drive

已淘汰的方法