質問編集履歴
1
ソースコードを追加しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -15,17 +15,35 @@
|
|
|
15
15
|
### 該当のソースコード
|
|
16
16
|
|
|
17
17
|
```GAS
|
|
18
|
+
function onFileChange(e) {
|
|
19
|
+
// 最新版フォルダとバックアップフォルダのIDを取得
|
|
20
|
+
const latestFolderId = "YOUR_LATEST_FOLDER_ID"; // 最新版フォルダのIDを置き換えてください
|
|
21
|
+
const backupFolderId = "YOUR_BACKUP_FOLDER_ID"; // バックアップフォルダのIDを置き換えてください
|
|
22
|
+
|
|
23
|
+
// トリガーされたファイルを取得
|
|
18
|
-
|
|
24
|
+
const file = e.file;
|
|
25
|
+
const fileName = file.getName(); // ファイル名を取得
|
|
26
|
+
|
|
27
|
+
// 最新版フォルダ内の同名ファイルを取得
|
|
28
|
+
const latestFolder = DriveApp.getFolderById(latestFolderId);
|
|
29
|
+
const files = latestFolder.getFilesByName(fileName);
|
|
30
|
+
|
|
31
|
+
// 同名ファイルが存在する場合
|
|
32
|
+
if (files.hasNext()) {
|
|
33
|
+
const backupFile = files.next(); // 同名ファイルを取得
|
|
34
|
+
backupFile.moveTo(DriveApp.getFolderById(backupFolderId)); // バックアップフォルダへ移動
|
|
35
|
+
}
|
|
36
|
+
}
|
|
19
37
|
```
|
|
20
38
|
|
|
21
39
|
### 試したこと・調べたこと
|
|
22
40
|
- [ ] teratailやGoogle等で検索した
|
|
23
41
|
- [ ] ソースコードを自分なりに変更した
|
|
24
42
|
- [ ] 知人に聞いた
|
|
25
|
-
- [x] その他
|
|
43
|
+
- [x] その他(Geminiに聞いた)
|
|
26
44
|
|
|
27
45
|
##### 上記の詳細・結果
|
|
28
|
-
|
|
46
|
+
ファイルが更新されたときをトリガーにする方法がわからない
|
|
29
47
|
|
|
30
48
|
### 補足
|
|
31
49
|
特になし
|