Google Drive API: find a file by name using wildcards? - google-drive-api

When using the Google Drive API v3, can one search for a file by its name using wildcards or regular expressions? The docs don't mention anything.
I am trying to match a set of files whose names have the format
backup_YYYY-MM-DD-XXXX_NameOfWebsite_xxxxxxxxxx.zip
And am wondering what's the best way to construct a pattern that might match it. Of course, I could follow the docs and just do something like:
q="name contains 'backup' and name contains 'NameOfWebsite'"
But if I need to match a different pattern, or something with more than 2 distinctive strings in its filename ("backup_" and "NameOfWebsite"), you can quickly see what a pain would be to construct a query in that way:
q="name contains 'string1' and name contains 'string2' and name contains...

Answer:
You can't use a wildcard in the middle of a file name when making a Drive.list request with a q parameter.
More Information:
The name field only takes three operators - =, != and contains:
The = operator is regular equivalence and with this you can not use a wildcard.
name = 'backup*' will return no results.
The != operator is not equivalence, not relevant here but does the opposite of =
The contains operator. You can use wildcards with this, but with restrictions:
name contains 'backup*' will return all files with filenames starting with the string backup.
name contains '*NameOfWebsite' will return all files with filenames that have a word starting with the string NameOfWebsite. The file name backup0194364-NameOfWebsite.zip will not be returned, because there is no space before the string.
Therefore, the only way for this to work is if you do it the way you have already started to realise; string chaining:
name contains 'backup' and name contains 'NameOfWebsite' and name contains ...
References:
Files: list | Google Drive API | Google Developers
Search for files | Google Drive API | Google Developers

Related

Extract Url from access Log in Splunk

This is the sample accessLog which is coming up in the Splunk ui.
{"timestamp":"2021-10-17T15:03:56,763Z","level":"INFO","thread":"reactor-http-epolpl-20","message":"method=GET, uri=/api/v1/hello1, status=200, duration=1, "logger":"reactor.netty.http.server.AccessLog"}
{"timestamp":"2021-10-17T15:03:56,763Z","level":"INFO","thread":"reactor-http-epolpl-20","message":"method=GET, uri=/api/v1/dummy1, status=200, duration=1, "logger":"reactor.netty.http.server.AccessLog"}
I want to extract the url and make a count for all the API's like how many times an API is hitted from the uri part(uri=/api/v1/dummy1)
(index=dummy OR index=dummy1) source=*dummy-service* logger=reactor.netty.http.server.AccessLog
| rex field=message "(?<url>uri.[\/api\/v1\/hello]+)"
| chart count by url
But it's not giving URL in a proper format. I tried various regex, but couldn't get the proper URL count.
I wanted to use this query to show the API counts in the Splunk dashboard.
The problem appears to be with the regular expression in the rex command. Square brackets ([]) in a regex denote a set from which any character can match, in any order. The example regex should match "/api/v1/hello", but also will match "iap/1v/ohell", "philo", and any other permutation of those characters. It will not, however, match "/api/v1/dummy1".
Try this query. The rex command here takes everything between "uri=" and the following comma as the url.
index=dummy OR index=dummy1 source=*dummy-service* logger=reactor.netty.http.server.AccessLog
| rex field=message "uri=(?<url>[^,]+)"
| chart count by url

Trying to pull the Name and/or ID of the code below, but can only pull the Job-Base-Cost

Below is the code I have now. It pulls the Job-Base-Cost just fine, however I cannot get it to pull the ID and or Name of the item. Can you help?
Link to the sites XML pull.
=importxml("link","//job-base-cost")
This is a sample of one line of the OP's XML file
<job-base-cost id="24693" name="Abaddon Blueprint">109555912.69</job-base-cost>
The OP wants to use the IMPORTXML function to report the ID and Name as well as the Job Cost from the XML data. Presently, the OP's formula is:
=importxml("link","//job-base-cost")
There are two options:
1 - One long column
=importxml("link","//#id | //#name | //job-base-cost")
Note //#id and //#name in the xpath query: // indicate nodes in the document (at any level, not just the root level) and # indicate attributes. The pipe | operator indicates AND. So the plain english query is to display the id, name and job-base-cost.
2 - Three columns (table format)
={IMPORTXML("link","//#name"),IMPORTXML("link","//job-base-cost"),IMPORTXML("link","//#id")}
This creates a series that will display the fields in each of three columns.
Note: there is an arrayformula that uses a single importXML function described in How do I return multiple columns of data using ImportXML in Google Spreadsheets?. Readers may want to look at whether that option can be implemented.
My thanks to #Tanaike for his comment which spurred me to look at how xpath works.

Google Spreadsheet, Substitute Integer with String

Hey there and thanks in advance.
I'm exporting the API of an application onto my spreadsheet, which works fine. Due to how the API was programmed however, some of the columns now contain the TypeID (an integer representing the "name") and not the actual name. I know what TypeID represents what Name, so what I'm looking for is a way to substitute all entries of said column with the actual name.
I have already begun to make a humongus switch case in the script editor that just checks every cell in that column and based of the contents substitues the right name, but as you can probably imagine that would take a while.
Just wondering if there is a "cleaner" and more effective way.
I'd recommend making a JSON object to represent your switch case and call that
i.e :
var jsonMap = {"TYPEID":"NAME"};
Then call :
jsonMap[fieldValue]
To return the correct value for that field
You could have the script trigger on row modification and have it translate that way.
Alternatively I'd recommend mapping the field before it is exported into sheets using the language you're exporting in and have the data enter the sheet correctly

Search in DriveApp doesn't find many files

I'm working with the DriveApp in Google Apps Script and try to find documents, that contain a certain word or phrase:
function SearchFile(Phrase, FolderID) {
var SearchString = 'fullText contains "' + Phrase + '" and "' + FolderID + '" in parents';
var files = DriveApp.searchFiles(SearchString);
return Output(files);
}
That works quite well so far, but it does only find a few files. I don't understand why. I have about 30 documents in that Folder that all contain the word "Hello". But search only find's 8 of them. Same with other words.
It seems like there is a bug in search?
Not enough information, but as you only menion that many files "contain" the word Hello, I will assume that the word Hello is anywhere in the name in your case.
First thing that comes to mind are the following 2 from the documentation
This one is when using the name field
The contains operator only performs prefix matching for a name. For
example, the name "HelloWorld" would match for name contains 'Hello'
but not name contains 'World'.
This one applies when using fullText fields
The contains operator only performs matching on entire string tokens
for fullText. For example, if the full text of a doc contains the
string "HelloWorld" only the query fullText contains 'HelloWorld'
returns a result. Queries such as fullText contains 'Hello' do not
return results in this scenario.

Search file names that contain a string

I have a module named flume and file names that include that module name, like flumeIndexController, flumePlugin etc. Now I've decided to rename the module to oozie so I want to have these files renamed to include new module's name like oozieIndexController, ooziePlugin.
How can I get a list of files than include the flume string (in file name) possibly using built-in search or through any other option?
Navigate | File... Ctrl + Shift + N using Default keymap.
You can narrow your search results (just specify parts of the path, e.g. /abc/ and it will show results in a folders that match such pattern/abbreviation). Alternatively -- just do a post-filtering by excluding unwanted results (see below).
This window has only 2 buttons -- one of which will display results in a more traditional and permanent "Search results" tool window (the one that you see when you do Find in Path and alike).