How to search for a particular text in a filename in G App Script? My full File name is "Daily Stock Summary Report Kadlunga20180426_061749_946.pdf". I would like to search for all file with the string "Daily Stock Summary Report Kadlunga" and copy it to folder name "Kadlunga" in G Drive. My current code works for the full file name. I am not exactly sure how to do this for p[art of the filename.
function moveFile() {
var dApp = DriveApp;
var folderIterator = dApp.getFoldersByName("Attachments");
var folder = folderIterator.next();
var filesIterator = folder.getFiles();
var Kadlunga = folder.getFoldersByName("Kadlunga").next();
var Napperby = folder.getFoldersByName("Napperby").next();
while (filesIterator.hasNext()){
var file = filesIterator.next();
var fileName = file.getName();
if(fileName == "Daily Stock Summary Report
Kadlunga20180426_061749_946.pdf")
{
file.makeCopy(Kadlunga);
}
if(fileName == "Daily Stock Summary Report
Napperby20180426_061749_958.pdf")
{
file.makeCopy(Napperby);
}
}
}
How about this modification?
Modification points :
searchFiles()
, files with the filename includingDaily Stock Summary Report
are retrieved.indexOf()
, files are categorized and imported to the folders ofKadlunga
andNapperby
.Modified script :
Note :
References :
If I misunderstand your question, I'm sorry.