Share via

Command - rename all pdf files in directory (and subdirectories) with sufix _YYYYMMDD-HHMM

Salka, Milan 111 Reputation points
2026-05-26T14:56:47.46+00:00

Hello,

exist any possibility how to create cmd/powershell command to find (in directory and in all subdirectories) all pdf files, read data of create pdf file (YYYYMMDDHHMM) and rename all PDF file with new sufix "_YYYYMMDD-HHMM" e.g. Name_YYYYMMDD-HHMM.pdf (only for when sufix isn´t yet exist).

Thank you.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

3 answers

Sort by: Most helpful
  1. Tsingtao Kai 80 Reputation points
    2026-05-28T06:50:31.5733333+00:00

    Hi

    Firstly,review.

    Get-ChildItem -Path "C:\your catlog" -Recurse -Filter *.pdf |

    Rename-Item -NewName { 
    
        $_.Name -replace '(?i)\.pdf$', ("_" + $_.LastWriteTime.ToString('yyyyMMdd-HHmm') + '.pdf') 
    
    } -WhatIf
    

    Secondly,rename

    Get-ChildItem -Path "C:\your catlog" -Recurse -Filter *.pdf |

    Rename-Item -NewName { 
    
        $_.Name -replace '(?i)\.pdf$', ("_" + $_.LastWriteTime.ToString('yyyyMMdd-HHmm') + '.pdf') 
    
    }
    

    Was this answer helpful?

    0 comments No comments

  2. Harry Phan 20,455 Reputation points Independent Advisor
    2026-05-26T15:42:18.36+00:00

    You can achieve this with PowerShell by combining Get-ChildItem to enumerate PDFs, Get-ItemProperty to read the CreationTime, and Rename-Item to append the suffix only when it doesn’t already exist. A reliable approach is:

    Get-ChildItem -Path "C:\Your\Directory" -Recurse -Filter *.pdf | ForEach-Object {
        $creation = $_.CreationTime.ToString("yyyyMMdd-HHmm")
        $baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
        if ($baseName -notmatch "\d{8}-\d{4}$") {
            $newName = "$baseName" + "_" + $creation + ".pdf"
            Rename-Item -Path $_.FullName -NewName $newName
        }
    }
    

    This script traverses all subdirectories, formats the timestamp as YYYYMMDD-HHMM, and renames only if the suffix isn’t already present. Make sure you run it with sufficient permissions in the target directory, and test first on a small set of files to confirm the naming convention before applying it broadly.

    Was this answer helpful?

    0 comments No comments

  3. AI answer

    2026-05-26T14:57:08.4166667+00:00

    Use PowerShell with Rename-Item and a recursive file search, then build the new name from the file’s creation time and append the suffix only if it isn’t already present.

    Example script:

    Get-ChildItem -Path 'C:\Path\To\Root' -Recurse -Filter *.pdf | ForEach-Object {
        $creation = $_.CreationTime
        $stamp = $creation.ToString('yyyyMMdd-HHmm')
    
        $baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
        $ext      = $_.Extension
    
        # Skip if suffix already present
        if ($baseName -match '_\d{8}-\d{4}$') {
            return
        }
    
        $newName = "$baseName`_$stamp$ext"
    
        Rename-Item -Path $_.FullName -NewName $newName
    }
    

    Notes:

    • Get-ChildItem -Recurse -Filter *.pdf finds all PDF files in the directory and subdirectories.
    • CreationTime is formatted as YYYYMMDD-HHMM.
    • The regex '_\d{8}-\d{4}$' checks whether a suffix like _20240526-1430 already exists and skips those files.
    • Rename-Item changes only the name; it does not move or overwrite items.

    If running from the target directory, -Path can be '.' instead of a full path.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.