0
votes

My question is simple and described in the Title.

I would like to write a script in App Script, that will search and list all the files in my Drive (Folders and Subfolders) that labels/restricted is false.

I could fetch all files and check one by one, but this is very time consuming script.

Thank you in advance.

UPDATE:

To be more specific I use the Script Editor in a Google Spreadsheet. I have enabled the Drive API in Script Editor in case I need it.

A simple search I use to find files that the modified date in one hour ago is the following:

var today     = new Date(); 
var oneHourAgo = new Date(today.getTime() - 1 * 1 * 60 * 60 * 1000);
var startTime = oneHourAgo.toISOString();
var search = '(trashed = true or trashed = false) and (modifiedDate > "' + startTime + '")';
var files  = DriveApp.searchFiles(search);

Now, I would like to search all the files in Drive that has the property label.restricted equals false.

1
What have you tried? There are similar questions that could get you most of the way there: How to list all files (or only certains type of files) inside a main folder and all its subfolders in Google Drive using GAS?, List all files in a folder, including files in sub folders, and others. Further, it's not clear what technology you're asking about; Google Apps Script and the Google Drive API are not the same thing.Mogsdad
I updated my post to be more specific.Loukas Nikolaidis
cannot check now but looking at your update I think that this can a way to go: DriveApp.searchFiles("properties has { key='label.restricted' and value='false' }");a-change
Below script does not work: (error: invalid query) DriveApp.searchFiles("properties has { key='label.restricted' and value='false' }");Loukas Nikolaidis

1 Answers

0
votes

It is possible in Apps Script if you use the Advanced Drive Services.

The advanced Drive service allows you to use the Google Drive web API in Apps Script. Much like Apps Script's built-in Drive service, this API allows scripts to create, find, and modify files and folders in Google Drive.

Drive.Files.list({'labels': {'restricted': true}}, fileId);

Be noted that this must be enabled before use.