Skip to main content

The first step is to create a database in Google Sheet in order to receive data into it,
The second step is to log in to Task in Asana in order to extract the drive link from it,
/ The drive link contains files. I wanted to extract specific data from each file in the drive link /
/ I knew that it was necessary to make the drive link downloadable in order to put it in my drive, but I did not know how?

I converted the drive link to a link with the download extension using python code, but when I upload the link to my drive, it attaches the link to a file in the folder I created./
This is what I have done so far
I just want to know what I need to do in Zapier to get going :
1 - Make the drive folder link downloadable
2 - How do I put the file in my drive?

 

How to Transfer Files Between Google Drive Links Using Google Apps Script

Google Drive is an essential tool for many, providing robust cloud storage solutions and seamless integration with Google Workspace. However, managing files between different Google Drive accounts or locations can sometimes be cumbersome. Thankfully, Google Apps Script offers a powerful way to automate and streamline these tasks. In this post, we'll walk through how to transfer a file from one Google Drive link to another using Google Apps Script.

Why Use Google Apps Script?

Google Apps Script is a JavaScript-based language that allows you to extend and automate Google Workspace products. By leveraging Apps Script, you can create custom functions, automate workflows, and interact with various Google services, including Google Drive.

Step-by-Step Guide to Transfer Files

Step 1: Set Up Your Script Environment

  1. Open Google Apps Script:
    • Go to Google Apps Script and start a new project.

Step 2: Write the Script

We'll write a script that:

  1. Takes the file ID from the source Google Drive link.
  2. Copies the file to the destination Google Drive folder.

Here's a simple script to achieve this:

 

Copy code this Code

function copyFiles() {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
let lastRow = sheet.getLastRow()

let driveApp = DriveApp;

for (let i = 2; i <= lastRow; i++) {
let sourceFolderId = sheet.getRange('B'+i).getValue();
let destinationFolderId = sheet.getRange('C'+i).getValue();
Logger.log('${sourceFolderId},${destinationFolderId}');

// Get the source folder
let sourceFolder = DriveApp.getFolderById(sourceFolderId);

// Get files from the source folder
let getFiles = sourceFolder.getFiles();

// Get DistnationFolderID
let destinationFolder = DriveApp.getFolderById(destinationFolderId)

Logger.log(getFiles)

// Loop through each file and copy it to the destination folder

while (getFiles.hasNext()) {
let file = getFiles.next();

// const destinationFolder = DriveApp.getFolderById(destinationFolderId);

let copy = file.makeCopy(destinationFolder)

Logger.log(`Copied file: ${file.getName()} to ${destinationFolder}`);

}
}
}


Step 3: Run the Script

  1. Save the Project:
    • Give your project a name and save it.
  2. Execute the Function:
    • From the drop-down menu, select transferExample and click the play button (▶️) to run the script.

Step 4: Handle Permissions

The first time you run the script, you'll need to authorize it to access your Google Drive:

  1. Click Review Permissions.
  2. Choose your Google account.
  3. Click Allow to grant the necessary permissions.

Step 5: Verify the Transfer

After running the script, check your target Google Drive folder to ensure the file has been copied successfully. The Logger in Apps Script will also provide a URL to the copied file, confirming the transfer.

Tips for Effective Use

  • Error Handling: Enhance the script by adding more robust error handling to manage different scenarios (e.g., invalid IDs, permission issues).
  • Batch Transfers: Modify the script to handle multiple file transfers in one execution if you need to transfer several files at once.
  • Scheduling Transfers: Use Google Apps Script triggers to schedule file transfers at specific times or intervals.

Conclusion

Using Google Apps Script to transfer files between Google Drive links is a powerful and efficient way to manage your documents. This approach not only saves time but also ensures consistency and accuracy in file management. Give it a try and see how it can streamline your workflow in Google Workspace!