LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2021, 07:21 AM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Angry Google script: how can i download and execute this code?


I want to list all files (
Code:
$ find . -type f
) in a Google Drive folder (not necessarily mine). I found this page:

1) https://floffi.media/en/web/create-l...-drive-folder/

Which gives the solution:

2) https://script.google.com/macros/s/A...qlO6o6YHM/exec

But when i try to open (2), i am asked to login, and after that, it complains about permission, which i would choose to give, but then [] says that the script is blocked. How do i download this script for myself, and execute it? The execution may be in a browser (preferably), or in a phone. If the code shown in (1) is all that is needed, how do i execute it?

I have read that other solutions exist, but they might be slow. So, i want to see if this one can work, somehow.
 
Old 04-10-2021, 08:31 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,688

Rep: Reputation: Disabled
The script code is given at the first link (just scroll down to the end of the page):
Code:
function listAllFilesInFolder() {
    var foldername = "XYZ";
    var filename = "files_" + foldername;
    var folder = DriveApp.getFoldersByName(foldername).next();
    var sheet = SpreadsheetApp.create(filename).getActiveSheet();
    var file;
    var data = [];
    var re = /(?:\.([^.]+))?$/;
    var files = folder.getFiles();
    data.push([ "Name", "Extension", "Owner", "Date created",
                "Date modified", "Size", "Link" ]);
    while (files.hasNext()) {
        file = files.next();
        data.push([ file.getName(), "." + re.exec(file.getName())[1],
                    file.getOwner().getName(), file.getDateCreated(),
                    file.getLastUpdated(), file.getSize(), file.getUrl() ]);
    }
    sheet.getRange(1, 1, data.length, data[0].length
                  ).setValues(data).setNumberFormat("@STRING@");
    sheet.getRange(1, 1, 1, data[0].length).setFontWeight("bold");
    sheet.autoResizeColumns(1, data[0].length);
}

Last edited by shruggy; 04-10-2021 at 08:33 AM.
 
Old 04-10-2021, 08:36 AM   #3
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by shruggy View Post
The script code is given at the first link (just scroll down to the end of the page):
Code:
function listAllFilesInFolder() {
    var foldername = "XYZ";
    var filename = "files_" + foldername;
    var folder = DriveApp.getFoldersByName(foldername).next();
    var sheet = SpreadsheetApp.create(filename).getActiveSheet();
    var file;
    var data = [];
    var re = /(?:\.([^.]+))?$/;
    var files = folder.getFiles();
    data.push([ "Name", "Extension", "Owner", "Date created",
                "Date modified", "Size", "Link" ]);
    while (files.hasNext()) {
        file = files.next();
        data.push([ file.getName(), "." + re.exec(file.getName())[1],
                    file.getOwner().getName(), file.getDateCreated(),
                    file.getLastUpdated(), file.getSize(), file.getUrl() ]);
    }
    sheet.getRange(1, 1, data.length, data[0].length
                  ).setValues(data).setNumberFormat("@STRING@");
    sheet.getRange(1, 1, 1, data[0].length).setFontWeight("bold");
    sheet.autoResizeColumns(1, data[0].length);
}
Thank you for confirming. But i am totally lost on where to put this code. I am a perfect newbie for this kind of code, i think.
 
Old 04-10-2021, 09:18 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,382
Blog Entries: 3

Rep: Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773
Anything you can type in the terminal can be turned into a shell script and vice versa. The gist is to put it into a file and then set the permissions on that file so that it is executable. However, at the beginning stage, you might benefit from an overview of shell scripting.

If that tutorial does not meet your needs, level, or interest, then there are many, many others to choose from. The parts your script appear to use are functions and the find utility. Both are good to know, the latter is a very powerful utility which you will find very useful. The
 
Old 04-10-2021, 09:56 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,688

Rep: Reputation: Disabled
This is not a shell script, it's a Google Apps script (a sort of JavaScript I guess). The page I linked describes how to run it on a Google Drive folder.
 
1 members found this post helpful.
Old 04-10-2021, 09:57 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,382
Blog Entries: 3

Rep: Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773Reputation: 3773
Thanks. I was looking more at the example posted in the question. I'll have to read up on Google Apps Scripts, assuming that it is not a proprietary technology.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script with Menu and sub menu and in sub menu execute another shell script SHWE Linux - Newbie 9 11-03-2018 06:19 PM
LXer: Google murders Google Code, orders everyone off to GitHub and pals LXer Syndicated Linux News 2 03-13-2015 02:22 PM
LXer: Google Reader: Google Giveth and Google taketh away. Keep Calm and Carry On LXer Syndicated Linux News 0 04-09-2013 06:41 PM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
Limited user cannot execute a script from within a script, but root can. versaulis SUSE / openSUSE 5 12-01-2008 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration