How to get List of Files with Size from Google Drive Folder and Save into Excel Sheet

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • How to get List of Files with Size from Google Drive Folder and Save into Excel Sheet, in this video we are going to learn How to get List of Files with Size from Google Drive Folder and Save into Excel Sheet.
    Script:
    function listFolderContents() {
    var foldername = 'Final Logos'; // provide the name of Folder from which you want to get the list of files
    var ListOfFiles = 'ListOfFiles_' + foldername;
    var folders = DriveApp.getFoldersByName(foldername)
    var folder = folders.next();
    var contents = folder.getFiles();
    var ss = SpreadsheetApp.create(ListOfFiles);
    var sheet = ss.getActiveSheet();
    sheet.appendRow( ['name', 'link','sizeInMB'] );
    var var_file;
    var var_name;
    var var_link;
    var var_size;
    while(contents.hasNext()) {
    var_file = contents.next();
    var_name = var_file.getName();
    var_link = var_file.getUrl();
    var_size=var_file.getSize()/1024.0/1024.0;
    sheet.appendRow( [var_name, var_link,var_size] );
    }
    };
    #ExcelSheet #ExcelTricks #GoogleDrive

Komentáře • 52

  • @bobmcconnell3123
    @bobmcconnell3123 Před 7 měsíci +1

    This is brilliant, simple and exactly what I needed. I had never done App Scripting before and I don't know if I'm ready to be a coder yet but this one saved me hours and hours of time on a project. I thank you very much for taking the time to make a great post. BRAVO!

    • @TechBrothersIT
      @TechBrothersIT  Před 7 měsíci

      Thank you for leaving detailed and nice comments!!Glad to hear that it was helpful

  • @ernestachenbach4283
    @ernestachenbach4283 Před 5 měsíci +1

    Worked perfectly. Could have been a 2 minute tutorial, though - but thank you!

  • @FJ-gt6qw
    @FJ-gt6qw Před rokem +4

    Thank you for sharing this!!! Really easy to understand. I want to include parent folders though plus their subfolders, what changes in the code should be done? Thank you. Really appreciate it. :)

  • @tomekleddo8537
    @tomekleddo8537 Před 2 lety +7

    It's working, chief! However I had to modify slightly the code so it loads the list to the current file (and, of course, in order to clear anteriorly the active sheet every time as it is triggered periodically). Cheers 👍
    Code:
    function listFolderContents() {
    var foldername = 'YourFolderName'; // provide the name of Folder from which you want to get the list of files
    var ListOfFiles = 'ListOfFiles_' + foldername;

    var folders = DriveApp.getFoldersByName(foldername)
    var folder = folders.next();
    var contents = folder.getFiles();

    SpreadsheetApp.getActiveSheet().clear();
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
    sheet.appendRow( ['name', 'link','sizeInMB'] );

    var var_file;
    var var_name;
    var var_link;
    var var_size;
    while(contents.hasNext()) {
    var_file = contents.next();
    var_name = var_file.getName();
    var_link = var_file.getUrl();
    var_size=var_file.getSize()/1024.0/1024.0;
    sheet.appendRow( [var_name, var_link,var_size] );
    }
    };

    • @user-mc8cj3ls6m
      @user-mc8cj3ls6m Před rokem +2

      thats exactly what i want to do, do you mind sharing the code?

    • @tomekleddo8537
      @tomekleddo8537 Před rokem

      @@user-mc8cj3ls6m
      function listFolderContents() {
      var foldername = 'YourFolderName'; // provide the name of Folder from which you want to get the list of files
      var ListOfFiles = 'ListOfFiles_' + foldername;

      var folders = DriveApp.getFoldersByName(foldername)
      var folder = folders.next();
      var contents = folder.getFiles();

      SpreadsheetApp.getActiveSheet().clear();
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
      sheet.appendRow( ['name', 'link','sizeInMB'] );

      var var_file;
      var var_name;
      var var_link;
      var var_size;
      while(contents.hasNext()) {
      var_file = contents.next();
      var_name = var_file.getName();
      var_link = var_file.getUrl();
      var_size=var_file.getSize()/1024.0/1024.0;
      sheet.appendRow( [var_name, var_link,var_size] );
      }
      };

    • @balkiszaitoun3051
      @balkiszaitoun3051 Před rokem

      TypeError: Cannot read properties of null (reading 'clear')

  • @helenekruger5807
    @helenekruger5807 Před rokem +2

    Thanks so much! A brilliant script and just what I was looking for!

  • @fairikius
    @fairikius Před rokem +1

    WONDERFUL!

  • @user-du4tq4tu7j
    @user-du4tq4tu7j Před rokem +2

    Do you have this version for shared drive?

  • @Handlervideos
    @Handlervideos Před rokem

    Thanks a bunch, that helped me a lot

  • @gezegeninsani
    @gezegeninsani Před 2 lety +1

    dude thats useful tool. thanks for sharing.

  • @alexarockman3999
    @alexarockman3999 Před rokem +1

    This is wonderful, thank you!!

  • @augustusgoldfinger
    @augustusgoldfinger Před 2 lety

    Outstanding work friend

  • @lic.enriquesanchezgonzalez9649

    Thanks so much for the help! This has been useful for complete files, but now I've come up with an obstacle. Sometimes I search for a specific phrase, so only the files with that content appear, and next I want to get the filenames of that filtered list. Could you please suggest any option for this?

  • @JonathanAdjei
    @JonathanAdjei Před 2 lety +1

    Nice work.. thanks!

  • @brighnquisitive6217
    @brighnquisitive6217 Před 2 lety +1

    well done mein freund

  • @vanthanhduong
    @vanthanhduong Před rokem

    Thank you

  • @ofirronen
    @ofirronen Před 2 lety +4

    Hi, it works but not in subfolders....do you know how to make it work for google drive folder with a few subfolders? Thanks!

    • @moshiblum4664
      @moshiblum4664 Před rokem +1

      Thank you, amazing work!
      1. I'm Interested in knowing how to get this works for subfolders too.
      2. what will happen if I have the same folder names on the drive? will it take both, or just the first one?

    • @Sunkaless
      @Sunkaless Před rokem +1

      @@moshiblum4664 Hey! 8 months later but what the heck, maybe this helps someone else. By the code attached to the video, if two files have the same name, the code only catches the first one it find. Either just rename one of the folders (temporarily if you want to swtich back later), or if you have the same problem as me where you don't own the folder, I've reworked the code so you can specify the parent folder:
      function listFolderContents() {
      var parentFolderName = 'writeYourParentFolderNameHere'; // Name of the parent folder
      var subFolderName = 'writeYourSubFolderNameHere; // Name of the subfolder you're interested in
      var ListOfFiles = 'ListOfFiles_' + parentFolderName;
      // Get the parent folder
      var parentFolders = DriveApp.getFoldersByName(parentFolderName);
      var parentFolder = parentFolders.next();
      // Get all folders with the specified name within the parent folder
      var subfolders = parentFolder.getFoldersByName(subFolderName);
      // Iterate over each subfolder and retrieve its contents
      while (subfolders.hasNext()) {
      var folder = subfolders.next();
      var contents = folder.getFiles();
      var ss = SpreadsheetApp.create(ListOfFiles);
      var sheet = ss.getActiveSheet();
      sheet.appendRow(['name', 'link', 'sizeInMB']);
      var var_file;
      var var_name;
      var var_link;
      var var_size;
      // Process the files within the subfolder
      while (contents.hasNext()) {
      var_file = contents.next();
      var_name = var_file.getName();
      var_link = var_file.getUrl();
      var_size = var_file.getSize() / 1024.0 / 1024.0;
      sheet.appendRow([var_name, var_link, var_size]);
      }
      }
      }
      Big thanks to @TechBrothersIT for the original code, helped a bunch!

  • @HelderSilva-zi4hs
    @HelderSilva-zi4hs Před rokem +1

    Hi, Thank you for sharing such an amazing script, this is going to save a lot of time making links for files on my G Drive, but I'm having a problem with the timer limit from the App Script, I have so many files (around 16.000) that I can't create files within the 6 minutes limit that the App Script has, is there a way to bypass that?

  • @pertevdural4513
    @pertevdural4513 Před 4 měsíci

    is it possible to list only text files and total number of pages in an sheet? folder name, file name, file type, file page number, file size MB)

  • @shibayanbiswas7806
    @shibayanbiswas7806 Před 2 měsíci

    This code is great but it is not working if there is any sub folder in the drive. Is there any solution for it?

  • @jenniferprice7494
    @jenniferprice7494 Před rokem

    Thank you so much! First one I found that worked :)

  • @cvhaugn
    @cvhaugn Před rokem +1

    Hi, I really appreciate this but I have zero knowledge in coding. I just followed as instructed: copy paste the code in App Script, provided the folder name save and run but I am always getting "Error An unknown error has occurred, please try again later." How can I trace what I'm missing? Thank you.

  • @AndreasLenski-ni9mh
    @AndreasLenski-ni9mh Před 2 měsíci

    Does it work with Shared Folders as well? I get an error: "Exception: Cannot retrieve the next object: iterator has reached the end."

  • @ridhofuadin6248
    @ridhofuadin6248 Před rokem +1

    is there a way to get the list of files in drive contain more than 1000 data??

  • @marcoa9944
    @marcoa9944 Před rokem

    Hey I used the code it worked great but how do I update it when I add more items to the drive folder?

  • @demimasa-gb7uc
    @demimasa-gb7uc Před rokem

    question, how to get length videos? what code do we have to use?

  • @rudroroy1054
    @rudroroy1054 Před 2 lety +1

    What is the language used to create the script?

  • @miquelvillartamartinez6855

    Not working if there are folders with same name. How to handle then? And how to look recursively? Any idea?

  • @thomvillas
    @thomvillas Před rokem

    I have a way:
    Step 1: open the google drive, show the list folder in google drive.
    Step 2: scrolling capture the screen
    Step 3: Trim the picture have just capture
    step 4: use web changing image to excel file

  • @bhavanilakshmipathy6113

    The google spread sheet is showing only the headers. Am I doing something wrong?

  • @user-bb9dw5wf1t
    @user-bb9dw5wf1t Před rokem

    Hi, is there a way to list all files of subfolders in 1 folder ?

    • @maureenmallach5019
      @maureenmallach5019 Před rokem

      Not sure if you were looking for the same thing I was, but I need a list of all Folder Names that existed in a Shared Drive, vs. Files Names. I tweaked the code to below and it worked like a charm. To be clear, this will ONLY give you the Folders Names in the Parent Folder. Any Files that are in the folder as well are not included.
      function listFolderContents() {
      var foldername = 'Clients'; // provide the name of Folder from which you want to get the list of files
      var ListOfFiles = 'ListOfFiles_' + foldername;

      var folders = DriveApp.getFoldersByName(foldername)
      var folder = folders.next();
      var contents = folder.getFiles();

      var ss = SpreadsheetApp.create(ListOfFiles);
      var sheet = ss.getActiveSheet();
      sheet.appendRow( ['name', 'link','sizeInMB'] );

      var var_file;
      var var_name;
      var var_link;
      var var_size;
      while(contents.hasNext()) {
      var_file = contents.next();
      var_name = var_file.getName();
      var_link = var_file.getUrl();
      var_size=var_file.getSize()/1024.0/1024.0;
      sheet.appendRow( [var_name, var_link,var_size] );
      }
      };

  • @owkprasanthkumar7292
    @owkprasanthkumar7292 Před 2 lety

    Can you please share the script as was mentioned on the video?

    • @TechBrothersIT
      @TechBrothersIT  Před 2 lety +2

      Script is added in the Description, please take look, Thanks For Your Comment.

  • @kimberlywilliams1606
    @kimberlywilliams1606 Před rokem

    Will this update automatically when a new file or folder is added?

    • @Lonewolf-
      @Lonewolf- Před rokem

      Nope you have to re run it

  • @stephanieodchigue595
    @stephanieodchigue595 Před 2 lety

    Hi! Can you use this for a shared Google drive?

  • @RyguyThaFlyguy
    @RyguyThaFlyguy Před rokem

    what about get thumbnail of an image

  • @johnschimandle9506
    @johnschimandle9506 Před rokem

    It worked but was not recursive so it did not traverse the folder hierarchy that was inside the folder. Did anyone take the time to make this a recursive algorithm?

    • @Lonewolf-
      @Lonewolf- Před rokem

      The too comment has a reply in which he has given the for code for this check that out

  • @CrynogarTM
    @CrynogarTM Před rokem +1

    I killed that script by having 160.222.333.111 Files in my Google Drive. 2238 GB of Data

  • @enriquerochamatus
    @enriquerochamatus Před rokem

    ooops.... Houston we have a problem:
    Google is blocking the app since it's trying "to access sensitive info"
    This app is blocked
    This app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access.

    • @Lonewolf-
      @Lonewolf- Před rokem

      Did you try to share the folder