Skip to content

Instantly share code, notes, and snippets.

@Denperidge
Last active January 2, 2021 12:47
Show Gist options
  • Save Denperidge/5608a5c265f65131a9bb936ade6b54b2 to your computer and use it in GitHub Desktop.
Save Denperidge/5608a5c265f65131a9bb936ade6b54b2 to your computer and use it in GitHub Desktop.
Prepend Date modified/LastWriteTime to all files in directory and subdirectories using Powershell 7 Core
@echo off
REM Bat file intended to allow drag and drop of directories, as well as bypassing executionpolicy temporarily (instead of having to change it machine wide for a while)
pwsh -ExecutionPolicy Bypass -File "%~dp0prepend-date-recursive.ps1" "%1%"
$dir = $args
write-host $dir
$files = Get-ChildItem -Path "$dir" -Recurse -File |
Where-Object { -not $_.Name.Contains("__") } |
Rename-Item -NewName {$_.LastWriteTime.ToString("yyyyMMdd_HHmmss__") + $_.Name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment