The following code returns "Invalid query" error if the file name contains double-quotes (")
It would probably fail as well for other 'special' characters, but I am only aware of the " so far
Question: How to avoid this error and find the file(s) with that name?
function getFilesByName(fileName, folderId) {
var query = Utilities.formatString('"%s" in parents and trashed = false and mimeType != "application/vnd.google-apps.folder" and title = "%s"', folderId, fileName);
var files, pageToken, items = [];
do {
files = Drive.Files.list({
q: query,
maxResults: 100,
pageToken: pageToken
});
if (files.items && files.items.length > 0) items = items.concat(files.items);
pageToken = files.nextPageToken;
} while (pageToken);
return items;
}
var files = getFilesByName('a filename with "quotes" within?', 'root');
Thanks, Fausto