All posts
powershellexcelautomationdocument-managementsortxopen-source

Bulk Rename and Sort Files (from Excel) with PowerShell

Synaplan Team18 views

Every office has that spreadsheet — the one from compliance, the tax advisor, or the auditor — listing hundreds of filenames that need to be renamed, moved, or archived. Doing it by hand is tedious and error-prone. Doing it with a script shouldn't require a computer-science degree.

We built extract-filenames.ps1, a free, open-source PowerShell script that reads any column from an Excel file and turns each value into a ready-to-run console command. No Excel installation required — it runs entirely on PowerShell 7 and the lightweight ImportExcel module, which it installs automatically on first run.

The Problem

Imagine your tax advisor sends you a spreadsheet with 500 rows. Column B contains the original filenames; column D has the new names they expect. You need to rename every single file before the next audit deadline.

Or maybe your compliance department maintains a master list of contracts that must be copied into a specific folder structure. Either way, the pattern is the same: data lives in Excel, but the work happens on the filesystem.

How It Works

The script has three modes:

Discovery — find out what's in the spreadsheet before you act:

# List all tabs (worksheets)
./extract-filenames.ps1 contracts.xlsx -ListTabs

# List column headers in a specific tab
./extract-filenames.ps1 contracts.xlsx "Audit 2026" -ListColumns

Extraction — pull values from any column, referenced by name, letter, or index:

# By header name
./extract-filenames.ps1 contracts.xlsx "Audit 2026" Filename

# By Excel column letter
./extract-filenames.ps1 contracts.xlsx "Audit 2026" B

# By numeric index
./extract-filenames.ps1 contracts.xlsx 1 3

Wrapping — turn each value into a file operation using the -Wrap flag, where {} is replaced by the extracted value:

# Generate rename commands
./extract-filenames.ps1 data.xlsx Sheet1 B -Wrap 'Rename-Item "{}" "AUDIT-{}"'

# Copy files to an archive
./extract-filenames.ps1 data.xlsx Sheet1 B -Wrap 'Copy-Item "{}" "D:\archive\"'

# Move files into a compliance folder
./extract-filenames.ps1 data.xlsx Sheet1 B -Wrap 'Move-Item "{}" "C:\Compliance\2026\"'

The output is plain text — one command per line. You can review it first, then pipe it to Invoke-Expression to execute:

# Review first (safe)
./extract-filenames.ps1 data.xlsx Sheet1 B -Wrap 'Copy-Item "{}" "D:\archive\"'

# Then execute
./extract-filenames.ps1 data.xlsx Sheet1 B -Wrap 'Copy-Item "{}" "D:\archive\"' | Invoke-Expression

Because the output is pipe-friendly, you can also filter, count, or redirect it:

# Only PDFs
./extract-filenames.ps1 data.xlsx Sheet1 C | Where-Object { $_ -like '*.pdf' }

# Save the list to a text file
./extract-filenames.ps1 data.xlsx Sheet1 C > filenames.txt

Why We Built It — The SortX Connection

At Synaplan, we develop SortX, an AI-powered document classification plugin that automatically sorts files into categories like contract, invoice, letter, or research using a three-step pipeline: fast regex matching, AI text classification, and vision-based fallback for scanned documents.

Document classification with Synaplan AI

After SortX classifies hundreds of documents, the results often need to be acted upon in bulk — renaming files to match a naming convention, copying them into department-specific folders, or preparing them for a tax audit. That's exactly where extract-filenames.ps1 comes in.

A typical workflow looks like this:

  1. SortX classifies your documents and exports results to an Excel file
  2. extract-filenames.ps1 reads the classification results and generates the file operations
  3. You review and execute — with full control over every step

This combination gives you AI-powered intelligence for what to do with your files, and a simple, auditable script for how to do it.

Requirements

  • PowerShell 7+ — available on Windows, macOS, and Linux (install guide)
  • No Excel installation needed — the script uses the open-source ImportExcel module and installs it automatically on first run

Get Started

The script is open source and available on GitHub:

github.com/metadist/synaplan-tools/tree/master/XLSX-extractor-ps

Clone the repo, run the script, and turn your next spreadsheet into a batch operation in seconds.


Synaplan is an open-source AI knowledge management platform. SortX is our document classification plugin that combines regex rules, AI text analysis, and vision models to automatically sort your files. Learn more at synaplan.com.