Menu

Batch-Renaming Users' Files With No Backend: File System Access API, the Firefox/Safari Fallback, and Why I Ship a ZIP Anyway
📰

Batch-Renaming Users' Files With No Backend: File System Access API, the Firefox/Safari Fallback, and Why I Ship a ZIP Anyway

DEV Community: javascript·Nibbo·14 days ago
#voXNWYl6
#devtojavascript#devto#dev#files#file
Reading 0:00
15s threshold

A small feature request: "I have 80 invoice PDFs called invoice (12).pdf . Can your tool rename them to 2026-10-15_Acme_550.00.pdf based on what's inside?" Reading the PDF and extracting the date, vendor and amount is the fun part. Actually renaming the files on the user's disk turned out to be the tricky part. Here are the three approaches I tried.

Option 1: File System Access API

Chromium browsers let you ask for a directory handle and write to it:

const dir = await window . showDirectoryPicker ({ mode : ' readwrite ' }); for await ( const [ name , handle ] of dir . entries ()) { if ( handle . kind !== ' file ' || ! name . endsWith ( ' .pdf ' )) continue ; const file = await handle . getFile (); const newName = await buildName ( file ); if ( handle . move ) await handle . move ( newName ); // in-place rename }

Enter fullscreen mode

Exit fullscreen mode

When it works, it's magical: files are renamed in place, no downloads. The catches:

Availability. showDirectoryPicker is Chromium-only.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.