Skip to content

Instantly share code, notes, and snippets.

@ALEXOTANO
Created September 16, 2023 18:39
Show Gist options
  • Save ALEXOTANO/d2258cb9f416601b09bddcc285e52344 to your computer and use it in GitHub Desktop.
Save ALEXOTANO/d2258cb9f416601b09bddcc285e52344 to your computer and use it in GitHub Desktop.
Change names of files in a directory base on date
$directoryPath = "D:\projects\ai\assets\out"
$files = Get-ChildItem -Path $directoryPath | Sort-Object CreationTime
$i = 1
foreach ($file in $files) {
# Get the file extension
$fileExtension = $file.Extension
# Create the new filename with a sequential number (padded to four digits)
$newFileName = "{0:D4}{1}" -f $i, $fileExtension
# Build the full path for the new filename
$newFilePath = Join-Path -Path $directoryPath -ChildPath $newFileName
# Rename the file
Rename-Item -Path $file.FullName -NewName $newFilePath
# Increment the counter
$i++
}
Write-Host "Archivos Renombrados Correctamente."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment