Screenshot of example folder structure in Google Drive |
The script makes use of 4 'loops' with the option to define how many folders/files you want to create at each level. There is an initial top row of folders each with files, then a row of sub-folders under this each with files too.
Selecting to create 5 of each via the parameters would produce 175 items in total, within about 8 minutes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createFoldersFiles() { | |
// get spreadsheet | |
var ss = SpreadsheetApp.getActive(); | |
var configSheet = ss.getSheetByName('Config'); | |
// get Drive Parent folder ID | |
var parentFolderID = configSheet.getRange(1, 2).getValue(); | |
var parentFolder = DriveApp.getFolderById(parentFolderID); | |
// get Google Doc Template file | |
var templateDocID = configSheet.getRange(2, 2).getValue(); | |
var templateDoc = DriveApp.getFileById(templateDocID); | |
// set parameters | |
var folders = 2; | |
var files = 2; | |
var subFolders = 2; | |
var subFiles = 2; | |
// create folder(s) | |
for (var p=0; p<folders; p++) { | |
var newFolderName = 'Folder ' + (p+1); | |
var newFolderId = parentFolder.createFolder(newFolderName).getId(); | |
var newFolder = DriveApp.getFolderById(newFolderId); | |
ss.toast(newFolderName, 'Created Folder'); | |
// create file(s) | |
for (var h=0; h<files; h++) { | |
var newFileName = 'Folder ' + (p+1) + ' - File ' + (h+1); | |
var newFile = templateDoc.makeCopy(newFileName, newFolder); | |
ss.toast(newFileName, 'Created File'); | |
} | |
// create sub-folder(s) | |
for (var i=0; i<subFolders; i++) { | |
var newSubFolderName = 'Folder ' + (p+1) +' - Sub Folder ' + (i+1); | |
var newSubFolderId = newFolder.createFolder(newSubFolderName).getId(); | |
var newSubFolder = DriveApp.getFolderById(newSubFolderId); | |
ss.toast(newSubFolderName, 'Created Sub-Folder'); | |
// create sub-file(s) | |
for (var l=0; l<subFiles; l++) { | |
var newSubFileName = 'Sub Folder ' + (i+1) +' - Sub File ' + (l+1) | |
var newSubFile = templateDoc.makeCopy(newSubFileName, newSubFolder); | |
ss.toast(newSubFileName, 'Created Sub-File'); | |
} | |
} | |
} | |
} |
Hi - where did the project to move/copy files from MyDrive to Shared Drives?
ReplyDeleteWe have the same problem as many I guess, too many files in MyDrive and they need to be in Shared Drives. Any thoughts and solutions welcomed
Hi Richard
DeleteI'm afraid that's not a project I've got. I've played around with a few prototypes but never had anything I'm happy to release.
Kind regards
Phil
Hi Phil,
ReplyDeleteI would like to bulk create folders in a shared drive, with 3 subfolders in each. I kind of need this: https://www.pbainbridge.co.uk/2021/05/bulk-create-google-drive-folders-with.html with an extra 2 subfolders. How can I edit the scrip and matching sheets template to do this?
Thanks for everything you've shared!
Hi
DeleteThank you.
Yes you're going to need to create some extra columns for each of the subfolders. Then it's a matter of working with some loops to go through these extra columns (it's perfectly feasible, but requires some careful planning/thought about how to do the iterating). I can't really point at a specific line of code to just change as it needs more code writing/inserting.
Kind regards
Phil