DriveApp

Create a new Drive file

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

Get a file from Drive

function getFileFromDrive() {
  var filesIterator = DriveApp.getFilesByName('New HTML File');
  while (filesIterator.hasNext()) {
    var file = filesIterator.next();
    Logger.log(file.getAs(MimeType.HTML).getDataAsString());
  }
}

List of files on a user's Drive

function listAllFiles() {
  // Log the name of every file in the user's Drive.
  var files = DriveApp.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    Logger.log(file.getName());
  }
}

List of files in a folder

function listAllFilesInFolder() {
  var folderId = 'INSERT_FOLDER_ID_HERE';
  // Log the name of every file in the folder.
  var files = DriveApp.getFolderById(folderId).getFiles();
  while (files.hasNext()) {
    var file = files.next();
    Logger.log(file.getName());
  }
}

发送以下问题的反馈:

此网页
AdWords Scripts
AdWords Scripts
需要帮助?请访问我们的支持页面