Friday, March 13, 2026

PowerShell para organizar archivos por año mes y dia

 $origen = "D:\DeleteMe"

Get-ChildItem $origen -File | ForEach-Object {

    # Obtener fecha de modificación en formato YYYYMMDD

    $fecha = $_.LastWriteTime.ToString("yyyyMMdd")

    # Crear carpeta destino

    $carpetaDestino = Join-Path $origen $fecha

    if (!(Test-Path $carpetaDestino)) {

        New-Item -ItemType Directory -Path $carpetaDestino | Out-Null

    }

    # Mover archivo

    Move-Item $_.FullName $carpetaDestino

}