WeirdGeek

Data Science | Machine Learning | Automation

  • Data Analytics
  • Python
  • Data Science
  • Google Apps Script
  • Machine Learning
  • Artificial Intelligence
  • SQL Server

18/09/2019 By WeirdGeek Leave a Comment

Find and Copy files of specific types using Google Apps Script

When you want to find and copy files of specific types using Google Apps Script from a folder to another folder on Google Drive, this code for sure will come handy. As you know Google Apps Script has a functionality of running it automatically on a particular time (time driven trigger) or even driven trigger(like opening of a spreadsheet), this makes it the best possible services offered by google and specially when you want to interact between different services offered by Google (as shown in below image).

Finding and Copying files of specific types in a folder on Google Drive using Google Apps Script

Find and Copy files of specific types in a folder on Google Drive using Google Apps Script – Code :

//Code to list files in a folder and Copy CSV and Excel Files from a Source Folder to Destination Folder
function GetFilesInAFolder() {
var SourceFolder = DriveApp.getFolderById("SourceFolderID")
var DestinationFolder = DriveApp.getFolderById("DestinationFolderID")
var Files = SourceFolder.getFiles();
var CSVFiles = SourceFolder.getFilesByType(MimeType.CSV)
var ExcelFiles = SourceFolder.getFilesByType(MimeType.MICROSOFT_EXCEL)
while (CSVFiles.hasNext()) {
CSVFiles.next().makeCopy(DestinationFolder)
}
while (ExcelFiles.hasNext()){
ExcelFiles.next().makeCopy(DestinationFolder)
}

Basically in the above code what i did is, first created two variable having Source and Destination folder and then find the specific file types i.e. CSV and Microsoft Excel using the MimeType.CSV and MimeType.MICROSOFT_EXCEL respectively. And finally copied both files types to destination folder.

To get more detailed knowledge about Google Apps Script, you can check the official website. Also if you want to explore more codes/posts related to Google Apps Script on our website, then you can find it here.

If you have any questions or if you need any help please get in touch with me using the comment section below.

Related posts:

  1. Unzip files using Google Apps Script on Google Drive
  2. Rename files using Google Apps Script on Google Drive
  3. Google Apps Script Code to find the days of the week
  4. Import CSV file data to Google Spreadsheet using Google Apps Script

Filed Under: Google Apps Script Tagged With: code, Google, Google Apps Script, Google Drive, Microsoft Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe to my Blog !!

Enter your email below to subscribe my blog and get the latest post right in your inbox.

  • Home
  • Terms
  • Privacy
  • Contact Us

Copyright © 2025 · WeirdGeek · All trademarks mentioned are the property of their respective owners.