Moving Files In Google Drive Using Google Script

前端 未结 8 1352
终归单人心
终归单人心 2020-12-03 05:15

I\'m trying to create documents using information posted through Google forms, then once the document is created I would like to move the document into a shared folder for p

相关标签:
8条回答
  • 2020-12-03 06:13

    It looks like there is now a moveTo() function with the Drive API (advanced services) that makes it easy to move files:

    moveTo(destination)

    Moves this item to the provided destination folder.

    The current user must be the owner of the file or have at least edit access to the item's current parent folder in order to move the item to the destination folder.

    Here is some code I used to move all files from the "screenshot input" folder to the "screenshot processed" folder:

    var inputFolder = DriveApp.getFolderById(SCREENSHOT_INPUT_FOLDER_ID);
    var processedFolder = DriveApp.getFolderById(SCREENSHOT_PROCESSED_FOLDER_ID);
    
    var files = inputFolder.getFiles();
    while (files.hasNext()) {
        var file = files.next();
        file.moveTo(processedFolder);
    }
    
    0 讨论(0)
  • Use File.moveTo(destination).

    var newFileId = newDoc.getId();
    var newFile = DriveApp.getFileById(newFileId);
    newFile.moveTo(targetFolder);
    
    0 讨论(0)
提交回复
热议问题