อนุญาตให้สคริปต์สร้าง ค้นหา และแก้ไขไฟล์และโฟลเดอร์ใน Google ไดรฟ์ หากต้องการเข้าถึงไฟล์หรือโฟลเดอร์ ในไดรฟ์ที่แชร์ ให้ใช้บริการไดรฟ์ขั้นสูง
// 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()); }
พร็อพเพอร์ตี้
พร็อพเพอร์ตี้ | Type | คำอธิบาย |
---|---|---|
Access | Access | ennum แสดงถึงคลาสของผู้ใช้ที่มีสิทธิ์เข้าถึงไฟล์หรือโฟลเดอร์ได้ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์อย่างชัดเจน |
Permission | Permission | Enum คือรายการให้สิทธิ์ผู้ใช้ที่มีสิทธิ์เข้าถึงไฟล์หรือโฟลเดอร์ นอกเหนือจากผู้ใช้ที่ได้รับสิทธิ์ |
วิธีการ
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
continueFileIterator(continuationToken) | FileIterator | ดําเนินการปรับปรุงไฟล์ต่อโดยใช้โทเค็นความต่อเนื่องจากตัวทําซ้ําก่อนหน้า |
continueFolderIterator(continuationToken) | FolderIterator | ดําเนินการอัปเดตโฟลเดอร์ต่อโดยใช้โทเค็นความต่อเนื่องจากตัวทําซ้ําก่อนหน้า |
createFile(blob) | File | สร้างไฟล์ในรูทไดรฟ์ของผู้ใช้จาก Blob ของข้อมูลที่กําหนดเอง |
createFile(name, content) | File | สร้างไฟล์ข้อความในรากไดรฟ์ของผู้ใช้โดยใช้ชื่อและเนื้อหานั้น |
createFile(name, content, mimeType) | File | สร้างไฟล์ในรูทไดรฟ์ของผู้ใช้โดยใช้ชื่อ เนื้อหา และประเภท MIME ที่ระบุ |
createFolder(name) | Folder | สร้างโฟลเดอร์ในรูทไดรฟ์ของผู้ใช้โดยใช้ชื่อที่ระบุ |
createShortcut(targetId) | File | สร้างทางลัดไปยังรหัสรายการในไดรฟ์ที่ระบุ และแสดงผล |
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey) | File | สร้างทางลัดไปยังรหัสรายการในไดรฟ์และรหัสคีย์ที่ให้ และส่งกลับมา |
enforceSingleParent(value) | void | เปิดหรือปิดใช้หรือปิดใช้การบังคับใช้ SingleParent สําหรับการเรียกทั้งหมดที่ส่งผลต่อรายการระดับบนสุด |
getFileById(id) | File | รับไฟล์ด้วยรหัสที่ระบุ |
getFileByIdAndResourceKey(id, resourceKey) | File | รับไฟล์ที่มีรหัสและคีย์แหล่งข้อมูลที่ระบุ |
getFiles() | FileIterator | รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ |
getFilesByName(name) | FileIterator | รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ |
getFilesByType(mimeType) | FileIterator | รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีประเภท MIME ที่กําหนด |
getFolderById(id) | Folder | เรียกโฟลเดอร์ด้วยรหัสที่ระบุ |
getFolderByIdAndResourceKey(id, resourceKey) | Folder | รับโฟลเดอร์ด้วยรหัสที่ระบุและคีย์ทรัพยากร |
getFolders() | FolderIterator | รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ |
getFoldersByName(name) | FolderIterator | รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ |
getRootFolder() | Folder | รับโฟลเดอร์ที่รูทไดรฟ์ของผู้ใช้ |
getStorageLimit() | Integer | รับจํานวนไบต์ที่ผู้ใช้ได้รับอนุญาตให้เก็บไว้ในไดรฟ์ |
getStorageUsed() | Integer | รับจํานวนไบต์ที่ผู้ใช้เก็บไว้ในไดรฟ์ในปัจจุบัน |
getTrashedFiles() | FileIterator | รับคอลเล็กชันไฟล์ทั้งหมดในถังขยะของไดรฟ์ของผู้ใช้ |
getTrashedFolders() | FolderIterator | รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในถังขยะของไดรฟ์ของผู้ใช้ |
searchFiles(params) | FileIterator | รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหาที่ระบุ |
searchFolders(params) | FolderIterator | รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหาที่ระบุ |
เอกสารโดยละเอียด
continueFileIterator(continuationToken)
ดําเนินการปรับปรุงไฟล์ต่อโดยใช้โทเค็นความต่อเนื่องจากตัวทําซ้ําก่อนหน้า วิธีนี้มีประโยชน์หากการประมวลผลตัววนซ้ําในการดําเนินการ 1 ครั้งเกินเวลาประมวลผลสูงสุด โดยทั่วไป โทเค็นแบบต่อเนื่องจะใช้ได้ 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
continuationToken | String | โทเค็นความต่อเนื่องจากตัวทริกเกอร์ไฟล์ก่อนหน้า |
ขากลับ
FileIterator
— คอลเล็กชันไฟล์ที่ยังคงอยู่ใน Iterer ก่อนหน้าเมื่อมีการสร้างโทเค็นความต่อเนื่อง
continueFolderIterator(continuationToken)
ดําเนินการอัปเดตโฟลเดอร์ต่อโดยใช้โทเค็นความต่อเนื่องจากตัวทําซ้ําก่อนหน้า วิธีนี้มีประโยชน์หากการประมวลผลตัววนซ้ําในการดําเนินการ 1 ครั้งเกินเวลาประมวลผลสูงสุด โดยทั่วไป โทเค็นแบบต่อเนื่องจะใช้ได้ 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
continuationToken | String | โทเค็นความต่อเนื่องจากตัววนซ้ําโฟลเดอร์ก่อนหน้านี้ |
ขากลับ
FolderIterator
คอลเล็กชันของคอลเล็กชันโฟลเดอร์ที่ยังอยู่ในตัวทําซ้ําก่อนหน้านี้เมื่อมีการสร้างโทเค็นความต่อเนื่อง
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.createFile(blob);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
blob | BlobSource | ข้อมูลสําหรับไฟล์ใหม่ |
ขากลับ
File
— ไฟล์ใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
createFile(name, content)
สร้างไฟล์ข้อความในรากไดรฟ์ของผู้ใช้โดยใช้ชื่อและเนื้อหานั้น ยกเว้นในกรณีที่ content
ใหญ่กว่า 50 MB
// Create a text file with the content "Hello, world!" DriveApp.createFile('New Text File', 'Hello, world!');
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อของไฟล์ใหม่ |
content | String | เนื้อหาของไฟล์ใหม่ |
ขากลับ
File
— ไฟล์ใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
createFile(name, content, mimeType)
สร้างไฟล์ในรูทไดรฟ์ของผู้ใช้โดยใช้ชื่อ เนื้อหา และประเภท MIME ที่ระบุ ยกเว้นในกรณีที่ content
ใหญ่กว่า 10 MB
// Create an HTML file with the content "Hello, world!" DriveApp.createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อของไฟล์ใหม่ |
content | String | เนื้อหาของไฟล์ใหม่ |
mimeType | String | ประเภท MIME ของไฟล์ใหม่ |
ขากลับ
File
— ไฟล์ใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
createFolder(name)
createShortcut(targetId)
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)
สร้างทางลัดไปยังรหัสรายการในไดรฟ์และรหัสคีย์ที่ให้ และส่งกลับมา คีย์ทรัพยากรคือพารามิเตอร์เพิ่มเติมที่จะต้องส่งผ่านเพื่อเข้าถึงไฟล์หรือโฟลเดอร์เป้าหมายที่แชร์โดยใช้ลิงก์
// 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
targetId | String | รหัสของไฟล์หรือโฟลเดอร์เป้าหมาย |
targetResourceKey | String | คีย์ทรัพยากรของไฟล์หรือโฟลเดอร์เป้าหมาย |
ขากลับ
File
— ทางลัดใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
enforceSingleParent(value)
เปิดหรือปิดใช้หรือปิดใช้การบังคับใช้ SingleParent สําหรับการเรียกทั้งหมดที่ส่งผลต่อรายการระดับบนสุด
ดูรายละเอียดเพิ่มเติมได้ที่บล็อก การลดความซับซ้อนของโครงสร้างโฟลเดอร์และโมเดลการแชร์ของ Google ไดรฟ์
// Turns on enforceSingleParent behavior for all calls affecting item parents. DriveApp.enforceSingleParent(true);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
value | Boolean | สถานะใหม่ของคําสั่งบังคับใช้นโยบายของ SingleSingle |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive
getFileById(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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสของไฟล์ |
ขากลับ
File
— ไฟล์ที่มีรหัสที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFileByIdAndResourceKey(id, resourceKey)
รับไฟล์ที่มีรหัสและคีย์แหล่งข้อมูลที่ระบุ คีย์ทรัพยากรคือพารามิเตอร์เพิ่มเติมที่จะต้องส่งผ่านเพื่อเข้าถึงไฟล์ที่แชร์โดยใช้ลิงก์
เขียนข้อยกเว้นของสคริปต์หากไม่มีไฟล์อยู่หรือผู้ใช้ไม่มีสิทธิ์เข้าถึงไฟล์
// 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสของไฟล์ |
resourceKey | String | คีย์ทรัพยากรของโฟลเดอร์ |
ขากลับ
File
— ไฟล์ที่มีรหัสที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFiles()
รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้
ขากลับ
FileIterator
— คอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFilesByName(name)
รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อไฟล์ที่จะค้นหา |
ขากลับ
FileIterator
— คอลเล็กชันไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFilesByType(mimeType)
รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีประเภท MIME ที่กําหนด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
mimeType | String | ประเภท MIME ของไฟล์ที่จะค้นหา |
ขากลับ
FileIterator
— คอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีประเภท MIME ที่กําหนด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFolderById(id)
เรียกโฟลเดอร์ด้วยรหัสที่ระบุ เขียนข้อยกเว้นของสคริปต์ออกหากไม่มีโฟลเดอร์ดังกล่าว หรือ ผู้ใช้ไม่มีสิทธิ์ในการเข้าถึง
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสของโฟลเดอร์ |
ขากลับ
Folder
— โฟลเดอร์ที่มีรหัสที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFolderByIdAndResourceKey(id, resourceKey)
รับโฟลเดอร์ด้วยรหัสที่ระบุและคีย์ทรัพยากร คีย์ทรัพยากรคือพารามิเตอร์เพิ่มเติมที่จะต้องส่งผ่านเพื่อเข้าถึงโฟลเดอร์ที่แชร์โดยใช้ลิงก์
เขียนข้อยกเว้นของสคริปต์หากไม่มีโฟลเดอร์อยู่หรือผู้ใช้ไม่มีสิทธิ์เข้าถึงโฟลเดอร์ดังกล่าว
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสของโฟลเดอร์ |
resourceKey | String | คีย์ทรัพยากรของโฟลเดอร์ |
ขากลับ
Folder
— โฟลเดอร์ที่มีรหัสที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFolders()
รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้
ขากลับ
FolderIterator
— คอลเล็กชันโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getFoldersByName(name)
รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
name | String | ชื่อของโฟลเดอร์ที่จะค้นหา |
ขากลับ
FolderIterator
— คอลเล็กชันโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่มีชื่อที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getRootFolder()
รับโฟลเดอร์ที่รูทไดรฟ์ของผู้ใช้
// 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
— โฟลเดอร์รูทไดรฟ์ของผู้ใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getStorageLimit()
รับจํานวนไบต์ที่ผู้ใช้ได้รับอนุญาตให้เก็บไว้ในไดรฟ์
// Gets the number of bytes the user can store in Drive and logs it to the console. console.log(DriveApp.getStorageLimit());
ขากลับ
Integer
— จํานวนไบต์ที่ผู้ใช้ได้รับอนุญาตให้จัดเก็บในไดรฟ์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getStorageUsed()
รับจํานวนไบต์ที่ผู้ใช้เก็บไว้ในไดรฟ์ในปัจจุบัน
// Gets the number of bytes the user is currently storing in Drive and logs it to the console. console.log(DriveApp.getStorageUsed());
ขากลับ
Integer
— จํานวนไบต์ที่ผู้ใช้กําลังจัดเก็บไว้ในไดรฟ์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getTrashedFiles()
รับคอลเล็กชันไฟล์ทั้งหมดในถังขยะของไดรฟ์ของผู้ใช้
// 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
— คอลเล็กชันของไฟล์ในถังขยะ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
getTrashedFolders()
รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในถังขยะของไดรฟ์ของผู้ใช้
// 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
— คอลเล็กชันโฟลเดอร์ในถังขยะ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
searchFiles(params)
รับคอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหาที่ระบุ เกณฑ์การค้นหาจะมีรายละเอียดอยู่ในเอกสารประกอบ Google ไดรฟ์ SDK โปรดทราบว่าบริการไดรฟ์ใช้เวอร์ชัน 2 ของ API ไดรฟ์ และคําค้นหาบางช่องต่างจากเวอร์ชัน 3 ตรวจสอบความแตกต่างระหว่าง 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
params | String | เกณฑ์การค้นหาตามรายละเอียดในเอกสาร SDK ของ Google ไดรฟ์ |
ขากลับ
FileIterator
— คอลเล็กชันของไฟล์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive
searchFolders(params)
รับคอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหาที่ระบุ เกณฑ์การค้นหาจะมีรายละเอียดอยู่ในเอกสารประกอบ Google ไดรฟ์ SDK โปรดทราบว่าบริการไดรฟ์ใช้เวอร์ชัน 2 ของ API ไดรฟ์ และคําค้นหาบางช่องต่างจากเวอร์ชัน 3 ตรวจสอบความแตกต่างระหว่าง 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()); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
params | String | เกณฑ์การค้นหาตามรายละเอียดในเอกสาร SDK ของ Google ไดรฟ์ |
ขากลับ
FolderIterator
คอลเล็กชันของโฟลเดอร์ทั้งหมดในไดรฟ์ของผู้ใช้ที่ตรงกับเกณฑ์การค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/drive.readonly
-
https://www.googleapis.com/auth/drive