Created
September 16, 2023 18:39
-
-
Save ALEXOTANO/d2258cb9f416601b09bddcc285e52344 to your computer and use it in GitHub Desktop.
Change names of files in a directory base on date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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