Skip to content

案内ファイル(移動しました.txt)に全ファイルの URL を記載する - #28

Draft
pollenjp wants to merge 1 commit into
mainfrom
claude/issue-27-bug-fix-9a6dcz
Draft

案内ファイル(移動しました.txt)に全ファイルの URL を記載する#28
pollenjp wants to merge 1 commit into
mainfrom
claude/issue-27-bug-fix-9a6dcz

Conversation

@pollenjp

@pollenjp pollenjp commented Aug 1, 2026

Copy link
Copy Markdown
Member

Fixes #27

何が問題だったか

Issue の 3 点は、根っこが 1 つでした。

フォルダの URL は必ず変わります。 ドメインをまたいでフォルダは移動できないので、移行先ではフォルダを作り直しています。作り直したフォルダは別のフォルダなので、案内ファイルに書かれた移行先フォルダのリンクが移行前と違うのは仕様どおりの挙動です(不具合ではありません)。

問題は、案内ファイルがその「変わってしまったフォルダのリンク」1 本しか持っていなかったことです。旧フォルダを開いた人は、目的のファイルへ辿り着く手段がありませんでした。

一方 ファイルの URL は変わりません。移動ではファイル ID がそのままだからです。つまり Issue のご提案どおり、全ファイルの URL を案内ファイルに書いておけば、フォルダの URL が変わる分をきれいに補えます。

変更内容

1. 全ファイルの URL を 1 行ずつ記載する

そのフォルダにあった全ファイルを、URL と「どうなったか」付きで列挙します。

このフォルダの中身を別の場所へ移動しました(1 件はこのフォルダに残っています)。

▼ 移行先フォルダ
https://drive.google.com/drive/folders/1AbCdEf...

▼ このフォルダにあったファイル 4 件(移動 2 / コピー 1 / このフォルダに残り 1)
- [移動] 提案書A.docx — https://drive.google.com/open?id=1MoVeD...
- [移動] 議事録 — https://drive.google.com/open?id=1DoCiD...
- [コピー] 見積.xlsx — https://drive.google.com/open?id=1NewID... (旧: https://drive.google.com/open?id=1OldID...)
- [未移動(他人所有)] 共有資料.pdf — https://drive.google.com/open?id=1SkIpP...

▼ URL について
・[移動] のファイルは ID が変わらないため、上記 URL は移行前と同じです。
...
  • URL は open?id= 形式に統一。Google ドキュメント/スプレッドシートなどのネイティブ形式でも通常ファイルでも同じ書き方で開けます
  • コピー救済されたファイルは ID が変わるため、旧 URL も併記します
  • 「URL について」の節で、何が変わって何が変わらないかを案内ファイル自体に書きました(Issue 3 点目の回答)

2. 中身が残っているのに「全部移動した」と書かない(バグ修正)

他人所有でスキップしたファイルや失敗したファイルはそのフォルダに残りますが、見出しは常に「このフォルダの中身は移動しました」でした。実際には残っているのに移動済みと読めてしまいます。残件数を出し分けるようにしました(処理途中の場合も明示します)。

3. 再実行・自動再開で過去の記録が消えない(バグ修正)

再実行や 4.5 分制限による自動再開では「まだ残っているファイルだけ」が処理されます。素直に書き出すと、前回移動したファイルの行が一覧から消えてしまいます。

  • 書き出しのたびに既存の案内ファイルを読み戻してマージします
  • 時間切れで中断する直前にも書き出すので、前半の記録が失われません
  • 行はファイル ID をキーにマージするため、再実行で状態が変わったファイルは重複せず最新に上書きされます

検証

  • pnpm typecheck 通過
  • GAS 実機なしで検証できるよう、ビルド後の JS からロジックを取り出して「書き出し → 読み戻し → マージ」の round-trip を確認(20 項目すべて成功)。ファイル名に区切り文字と同じ を含むケース、中断からの再開、再実行での上書き、見出しの出し分け、ドライラン、上限超過時の省略、ID 抽出を含みます

補足

  • 「【後片付け】空フォルダを削除」を実行すると、案内ファイルだけが残るフォルダは案内ごとゴミ箱に入ります(従来どおりの仕様)。**一覧を残したい場合は後片付けを実行しないでください。**教科書にも注意書きを追加しました
  • 1 フォルダあたりの記載は 5000 件を上限としました(巨大フォルダでの暴走よけ)。超過分は件数のみ記載します
  • 教科書 3.16 / 4章の関数表 / 6章 FAQ(「URL は変わるのか」の Q&A を新設)を更新しました

Generated by Claude Code

Folders cannot cross domains, so the destination folder is re-created and
its URL necessarily differs from the source folder's. The breadcrumb only
carried that one (changed) folder link, leaving no way to follow an
individual file from the old folder — even though moved files keep their
ID, and therefore their URL.

The breadcrumb now lists every file that was in the folder, one line each,
with its URL and what happened to it: moved (URL unchanged), copy-rescued
(new URL, old one shown alongside), or left behind because it is owned by
someone else or failed. A short section spells out which URLs survive the
migration and which do not.

Two correctness fixes fall out of this:

- The headline no longer claims the whole folder moved when files were
  skipped or failed and are still sitting there. It reports how many
  remain, and says so explicitly while a folder is still being processed.
- Records are merged with the existing breadcrumb, and flushed before the
  4.5-minute execution limit suspends a folder mid-way. Re-runs and
  auto-resume only process the files still present, so without merging the
  earlier entries would be dropped from the list.

Entries are keyed by file ID, so a re-run supersedes a file's previous
status instead of duplicating it. Listing is capped at 5000 files per
folder as a runaway guard, with the omitted count noted in the file.

Fixes #27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

所有権移動 script のバグ

2 participants