convert_encoding
Convert files between character encodings. Supports auto-detection, batch processing, backups, and dry-run previews, refusing unsafe conversions to prevent corruption.
Instructions
Convert files between encodings. Parameters: path (one file) OR paths (a batch — never both), to (required), from (omit to auto-detect), backup (write .bak first), dryRun (report only), allowLowConfidence, bom ("auto" default, "always", "never", "preserve"). Refuses rather than corrupting: a narrowing conversion (utf-8 to cp1251) names the characters the target lacks with line and column, and an untrusted detection names its best guess — confirm it with from, or pass allowLowConfidence=true. A source BOM is stripped before decoding; one contradicting an explicit from is an error. No-op if the file already holds the target bytes. In a batch one bad file does not stop the rest. Run dryRun over a project first. Examples: {"path": "D:\legacy\data.txt", "to": "utf-8", "backup": true} leaves data.txt.bak; {"paths": ["a.pas", "b.pas"], "to": "utf-8", "dryRun": true} previews a migration.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | ||
| bom | No | ||
| from | No | ||
| path | No | ||
| paths | No | ||
| backup | No | ||
| dryRun | No | ||
| allowLowConfidence | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dryRun | No | ||
| errors | No | ||
| hasBom | Yes | ||
| bomType | No | ||
| changed | Yes | ||
| message | Yes | ||
| results | No | ||
| backupPath | No | ||
| errorCount | No | ||
| successCount | No | ||
| sourceEncoding | No | ||
| targetEncoding | Yes |