Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created September 20, 2012 11:20
Show Gist options
  • Save hubgit/3755293 to your computer and use it in GitHub Desktop.
Save hubgit/3755293 to your computer and use it in GitHub Desktop.
List all files in a folder (Google Apps Script)
function listFilesInFolder() {
var folder = DocsList.getFolder("Maudesley Debates");
var contents = folder.getFiles();
var file;
var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Name", "Date", "Size", "URL", "Download", "Description", "Type"]);
for (var i = 0; i < contents.length; i++) {
file = contents[i];
if (file.getFileType() == "SPREADSHEET") {
continue;
}
data = [
file.getName(),
file.getDateCreated(),
file.getSize(),
file.getUrl(),
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
"audio/mp3"
];
sheet.appendRow(data);
}
};
@AkshAy-K125
Copy link

Looks like DocsList is deprecated by Google. You can use the below code to check the file name and ID.

/*
* Code is to check if I have a file named "ANA/20216/22.pdf" in my parent folder
*/


function findFileByNameIfPresentInAFolder(){
 var folder = DriveApp.getFolderById("<Enter your parent folder ID here>");
 var key = 'ANA/20216/22'+'.pdf';
  var list = [];
  var files = folder.getFiles();
  while (files.hasNext()){
    file = files.next();
   if(key == file.getName()){
      list.push(file.getId());
   }
    
  }
   Logger.log(list);
}

@sannykhan3777
Copy link

sannykhan3777 commented Mar 17, 2022

I want my firebase storage and google drive synced with each other like If I upload a file to my drive it should go to firebase storage too and if I upload a file on storage it should come to my drive too.
I also want to trigger my function when I upload file on google drive or firebase storage.
Is it possible guys?
I am able to upload the folder and the file to firebase storage but its hard coded.
I want a trigger so, when drive or firebase storage changes it should trigger the function and function should take the files name either they are on drive or firebase storage and then upload it to drive or firebase either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment