-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode.gs
More file actions
40 lines (32 loc) · 1.08 KB
/
code.gs
File metadata and controls
40 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function moveFiles() {
const rootFolder = DriveApp.getRootFolder();
const folders = {
'Test': DriveApp.getFolderById('Folder-ID-Here'), // Replace with actual folder ID
// Add more folders as needed
};
const files = rootFolder.getFiles();
const movedFiles = [];
while (files.hasNext()) {
const file = files.next();
const title = file.getName();
const matches = title.match(/\[(.*?)\]/);
// Check if the file is a supported type
const mimeType = file.getMimeType();
const supportedTypes = [
MimeType.GOOGLE_DOCS,
MimeType.GOOGLE_SHEETS,
MimeType.GOOGLE_SLIDES,
MimeType.GOOGLE_FORMS,
];
if (matches && supportedTypes.includes(mimeType)) {
const category = matches[1].trim();
const targetFolder = folders[category];
if (targetFolder) {
targetFolder.addFile(file);
rootFolder.removeFile(file);
movedFiles.push(file.getName());
}
}
}
Logger.log('Moved files: ' + movedFiles.join(', '));
}