rename_to_snake_case.ps1 - limehawk/rmm-scripts GitHub Wiki

rename_to_snake_case.ps1

Recursively rename all files and folders to snake_case format.

Overview

Recursively renames all files and folders in a directory to snake_case format. Converts spaces, hyphens, and other non-alphanumeric characters to underscores and lowercases all characters.

Purpose

Recursively renames all files and folders in a directory to snake_case format. Converts spaces, hyphens, and other non-alphanumeric characters to underscores and lowercases all characters.

Prerequisites

  • Windows 10/11
  • Write permissions to target directory

Configuration

Required Inputs

  • TargetPath : Directory path to process (recursive)

Settings

  • Converts to lowercase
  • Replaces non-alphanumeric characters with underscores
  • Trims leading/trailing underscores
  • Processes child items first (bottom-up) to avoid path issues

Data Sources & Priority

  1. Hardcoded values (target directory path)

Behavior

  1. Validates target directory exists
  2. Gets all files and folders recursively
  3. Reverses list (process children before parents)
  4. Renames each item to snake_case if different
  5. Reports each rename operation

Security Notes

  • No secrets in logs
  • Only renames files/folders, does not modify content
  • Cannot be undone - backup important directories first

Exit Codes

  • 0: Success
  • 1: Failure

Example Output

[ INPUT VALIDATION ]
--------------------------------------------------------------
Target Path : C:\Users\Example\Documents\MyFolder

[ OPERATION ]
--------------------------------------------------------------
Processing 15 items...
Renamed "My File.txt" to "my_file.txt"
Renamed "Another-File.pdf" to "another_file.pdf"
Renamed "Sub Folder" to "sub_folder"

[ RESULT ]
--------------------------------------------------------------
Status  : Success
Renamed : 12 items
Skipped : 3 items (already snake_case)

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • 2025-11-29 v1.0.0 Initial Style A implementation

Links