A simple interactive PowerShell script that uses a generative LLM (by default Google Gemini via the Generative Language API) to suggest descriptive, filesystem-safe filenames for all files in a folder — then previews and optionally applies the renames.
- Collects filenames in a folder and sends them to an LLM with your custom instruction (e.g., "Make filenames descriptive and professional").
- Requests a JSON array of new filenames (without extensions) to ensure predictable parsing.
- Previews the proposed renames and asks for confirmation before applying changes.
- Sanitizes suggested names to remove invalid filesystem characters and prevents overwriting existing files.
- Windows PowerShell (the script uses standard PowerShell cmdlets)
- curl available in the system PATH
- A valid Google Generative Language API key (set in the script)
- Can be modified to LLM of your choice.
- Set your API key in the script: $ApiKey = "YOUR_REAL_API_KEY"
- Run the script in PowerShell.
- When prompted:
- Enter the folder path containing files to rename.
- Enter a rename prompt (e.g., "Make filenames descriptive and professional").
- Review the LLM-proposed filenames shown in order.
- Confirm (Y) to apply the renames or cancel.
- The script enumerates files in the provided folder.
- It builds a prompt containing the user's instruction and the current filenames, asking the LLM to return a JSON array of new base filenames (same order, no extensions).
- The response is parsed, validated (count and JSON), previewed, sanitized, and then applied after user confirmation.
The script instructs the LLM to respond ONLY with a valid JSON array of strings (no file extensions), e.g.: ["Invoice_2025-09", "ProjectPlan_Backup", "Photo_Vacation_01"]
This strict format reduces parsing errors and accidental output noise.
- The script will not overwrite existing files; suggested renames that collide with existing filenames are skipped.
- It sanitizes filenames to remove characters invalid on Windows/Unix (, /, :, *, ?, ", <, >, |).
- Always review the preview before confirming.
- If curl is not found, install curl or run on a system with curl available.
- If the LLM response cannot be parsed as JSON, inspect the raw output printed by the script (it removes common Markdown fences before parsing).
- Ensure your API key is set and valid for the endpoint used.
MIT License